Visual Basic Foro
Programación => Visual Basic 6 => Mensaje iniciado por: erbuson en Abril 13, 2014, 05:56:24 pm
-
Pues esto, lo dicho en el título, como puedo leer el Texto que me aprece en un WebBrowser el cual me indica unicamente mi IP
<!--Beginning of IP Script-->
<script type="text/javascript" src="http://www.whatsmyip.us/showipsimple.php"> </script>
<!--End of IP Script-->
He conseguido encontrar este código que pegado en un archivo htm 'navegando hacia el mismo con un simple
WebBrowser1.Navigate App.Path & "\Mi_IP.htm"
Me devuelve la IP, pero quisiera saber como leer el texto devuelto para poder enviarlo directamente hacia un determinado archivo txt en dropbox para poder saber en cualquier momento desde el movil por ejemplo cual es la IP dinámica actual.
Gracias
MODIFICO ESTE PRIMER MENSAJE POR SI A ALGUIEN LE SIRVE EL SISTEMA, ES MUY SIMPLE
Dim Ip As String
Ip = WebBrowser1.Document.documentElement.innertext
Así de fácill
-
El metodo de siempre, http://checkip.dyndns.org/
Agarrá mi clase de request, y enviale un GET a dicho sitio. Luego saca el IP usando InStr y Left, o Mid.
Ejemplo
<html><head><title>Current IP Check</title></head><body>Current IP Address: 181.14.229.173</body></html>
PD: Una lastima que dyndns nos cierre las cuentas a los que eramos "free" desde hace años. Que soretes.
-
Hola, mi duda esta en como meter en un String el valor devuelto para poder utilizar el Mid y demás.
Gracias
-
Hola de nuevo:
Se me ha ocurrido utilizar la funcion para leer el TXT desde una URL
Option Explicit
'Tipos de Conexión
Private Const INTERNET_DEFAULT = 0
Private Const INTERNET_DIRECT = 1
Private Const INTERNET_PROXY = 3
Private Const INTERNET_FLAG_RELOAD = &H80000000
'UserAgent del Browser
Public Const scUserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; GTB6.5; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; msn OptimizedIE8;ESXL)"
'Funcion para Abrir URL
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hOpen As Long, ByVal sURL As String, ByVal sHeaders As String, ByVal lLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Declare Function HttpQueryInfo Lib "wininet.dll" Alias "HttpQueryInfoA" (ByVal hHttpRequest As Long, ByVal lInfoLevel As Long, ByRef sBuffer As Any, ByRef lBufferLength As Long, ByRef lIndex As Long) As Integer
'Cookie
Public Declare Function InternetGetCookie Lib "wininet.dll" Alias "InternetGetCookieA" (ByVal lpszUrlName As String, ByVal lpszCookieName As String, ByVal lpszCookieData As String, lpdwSize As Long) As Boolean
Public Function LeerDeURL(ByVal sURL As String) As String
On Error Resume Next
Dim hOpen As Long
Dim hOpenUrl As Long
Dim bDoLoop As Boolean
Dim bRet As Boolean
Dim sReadBuffer As String * 2048
Dim lNumberOfBytesRead As Long
Dim sBuffer As String
hOpen = InternetOpen(scUserAgent, INTERNET_DEFAULT, vbNullString, vbNullString, 0)
hOpenUrl = InternetOpenUrl(hOpen, sURL, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
bDoLoop = True
Do While bDoLoop
sReadBuffer = vbNullString
bRet = InternetReadFile(hOpenUrl, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
sBuffer = sBuffer & Left$(sReadBuffer, lNumberOfBytesRead)
If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
Loop
If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl)
If hOpen <> 0 Then InternetCloseHandle (hOpen)
LeerDeURL = sBuffer
End Function
Y me ha funcionado perfectamente:
Recibido = LeerDeURL("http://www.whatsmyip.us/showipsimple.php")
y me devuelve document.write("nnn.nnn.nnn.nnn"); con lo que ya puedo obtener la IP que está entre comillas.
Saludos
Edito para indicar que con el fin de no depender de terceros, acabo de subir al dominio de la empresa un pequeño archivo PHP con el siguiente contenido:
<? echo $_SERVER['REMOTE_ADDR'] ; ?>
Así al leer este archivo de la misma manera indicada, simplemente me devuelve nnn.nnn.nnn.nnn y ya no tengo que hacer nada mas.
-
HOLA!!!
Aca tengo armada una funcion que trae el ip externo, creo que es lo que necesitas:
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal sURL As String, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal LpszDir As String, ByVal FsShowCmd As Long) As Long
Private Const IF_FROM_CACHE = &H1000000
Private Const IF_MAKE_PERSISTENT = &H2000000
Private Const IF_NO_CACHE_WRITE = &H4000000
Private Const Webs As String = "http://bot.whatismyipaddress.com/ http://myip.dnsomatic.com/ http://ip.nfriedly.com/text"
Private Const BUFFER_LEN = 256
Private Function CheckExternalIp() As String
Dim IP As String
Dim URLs() As String: URLs = Split(Webs)
For x = 0 To UBound(URLs)
IP = Gurl(URLs(x))
If IsValidIp(IP) Then Exit For
Next
If IP = vbNullString Then MsgBox "Checkee su conexion a internet por favor, parece que esta fallando.", vbCritical, "Ups!": Unload Me
CheckExternalIp = IP
End Function
Public Function Gurl(sURL As String) As String
'seba123neo
Dim sBuffer As String * BUFFER_LEN, iResult As Integer, sData As String
Dim hInternet As Long, hSession As Long, lReturn As Long
hSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)
If hSession Then hInternet = InternetOpenUrl(hSession, sURL, vbNullString, 0, IF_NO_CACHE_WRITE, 0)
If hInternet Then
iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
sData = sBuffer
Do While lReturn <> 0
iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
sData = sData + Mid(sBuffer, 1, lReturn)
Loop
End If
iResult = InternetCloseHandle(hInternet)
Gurl = Replace(sData, Chr(0), vbNullString)
End Function
Private Function IsValidIp(strIpAddress) As Boolean
Dim aTmp
IsValidIp = False
aTmp = Split(strIpAddress, ".")
If UBound(aTmp) <> 3 Then Exit Function
For Each field In aTmp
If field > 255 Then Exit Function
Next
IsValidIp = True
End Function
Private Sub Form_Load()
Me.Show
Print CheckExternalIp
End Sub
Copia en un formulario en blanco y vas a ver como funciona! (solo tenes que llamar a CheckExternalIp y lo que esta devuelve es tu ip externo)
GRACIAS POR LEER!!!
-
yo no usaria webbrowser, directamente descargaria el texto de la web y listo, yo personalmente uso la de dyndns:
http://checkip.dyndns.org/ (http://checkip.dyndns.org/)
con una simple expresion regular podes hacer que solo queden los numeros y listo.
saludos.
-
yo no usaria webbrowser, directamente descargaria el texto de la web y listo, yo personalmente uso la de dyndns:
http://checkip.dyndns.org/ (http://checkip.dyndns.org/)
con una simple expresion regular podes hacer que solo queden los numeros y listo.
saludos.
No es el tema pero esta solucion que diste me ha caido del cielo para un asunto que queria resolver, gracias Sebas!!!
-
PD: Una lastima que dyndns nos cierre las cuentas a los que eramos "free" desde hace años. Que soretes.
no se cerro ninguna cuenta, simplemente se borra el host a los que pasan mas de 30 dias sin loguearse a la pagina web, basta con loguearse y dar de alta de nuevo el host y listo. lo mismo pasa ahora con el NO-IP y todos los servicios grandes. igualmente comprarse una cuenta no cuesta nada, en un año pagas 10 pesos por mes.
-
Gracias, al final en realidad creo que es lo que estoy haciendo, ya que con la segunda opcion leo el fichero php y en realidad me devuelve solamente la IP por lo que no necesito separar nada.
Además, al ponerla en el servidor de la empresa se que siempre la tendré accesible sin ningun problema.
Saludos
-
PD: Una lastima que dyndns nos cierre las cuentas a los que eramos "free" desde hace años. Que soretes.
no se cerro ninguna cuenta, simplemente se borra el host a los que pasan mas de 30 dias sin loguearse a la pagina web, basta con loguearse y dar de alta de nuevo el host y listo. lo mismo pasa ahora con el NO-IP y todos los servicios grandes. igualmente comprarse una cuenta no cuesta nada, en un año pagas 10 pesos por mes.
No seba, las cuentas free ya no van mas (al margen de lo qie decis vos). A mi me llego un mail diciendo que mi dominio free ya no funcionaria en 1 mes porque ya no admiten mas los free.
To our Dyn free hostname users:
For the last 15 years, all of us at Dyn have taken pride in offering you and millions of others a free version of our Dynamic DNS Pro product. What was originally a product built for a small group of users has blossomed into an exciting technology used around the world.
That is why with mixed emotions we are notifying you that in 30 days, we will be ending our free hostname program. This change in the business will allow us to invest in our customer support teams, Internet infrastructure, and platform security so that we can continue to strive to deliver an exceptional customer experience for our paying customers.
We would like to invite you to upgrade to VIP status for a 25% discounted rate, good for any package of Remote Access (formerly DynDNS Pro). By doing so, you'll have access to customer support, additional hostnames, and more.
-
tenes razon, no ofrecen mas cuentas free, solo de pago.
Pero como dije, las cuentas "free viejas" que ya estaban registradas no se cierran, solo se bloquean(te borran el host) si no te logueas durante 30 dias en la pagina, pero te dejan reactivarla de nuevo.
seria casi un crimen que borren de un plumazo millones de cuentas free 8)
del foro de dyndns sobre este tema.
Existing free hostnames will not be deleted if the account is logged into every 30 days.
-
tenes razon, no ofrecen mas cuentas free, solo de pago.
Pero como dije, las cuentas "free viejas" que ya estaban registradas no se cierran, solo se bloquean(te borran el host) si no te logueas durante 30 dias en la pagina, pero te dejan reactivarla de nuevo.
seria casi un crimen que borren de un plumazo millones de cuentas free 8)
del foro de dyndns sobre este tema.
Existing free hostnames will not be deleted if the account is logged into every 30 days.
Parece que no che!
To our Dyn free hostname users:
This email is an reminder that Dyn's free hostname program will be ending on Wednesday, May 7th -- 14 days from today. If you are receiving this email, you have one or multiple free hostnames with us.
In order to avoid any service disruption, you have the option to upgrade to VIP status at a one-time 25% discount, good for any package of Remote Access (formerly DynDNS Pro). By doing so, you'll have immediate access to customer support, additional hostnames, and more.
-
tenes razon, no ofrecen mas cuentas free, solo de pago.
Pero como dije, las cuentas "free viejas" que ya estaban registradas no se cierran, solo se bloquean(te borran el host) si no te logueas durante 30 dias en la pagina, pero te dejan reactivarla de nuevo.
seria casi un crimen que borren de un plumazo millones de cuentas free 8)
del foro de dyndns sobre este tema.
Existing free hostnames will not be deleted if the account is logged into every 30 days.
Parece que no che!
To our Dyn free hostname users:
This email is an reminder that Dyn's free hostname program will be ending on Wednesday, May 7th -- 14 days from today. If you are receiving this email, you have one or multiple free hostnames with us.
In order to avoid any service disruption, you have the option to upgrade to VIP status at a one-time 25% discount, good for any package of Remote Access (formerly DynDNS Pro). By doing so, you'll have immediate access to customer support, additional hostnames, and more.
si, hoy me llego tambien el email 8).