Obtener Wan IP en vb6

Iniciado por rapbyone, 2 Julio 2014, 23:04 PM

0 Miembros y 1 Visitante están viendo este tema.

rapbyone

Cita de: engel lex en  3 Julio 2014, 18:27 PM
usa MID o RIGHT para sacar el resto

aqui una referencia de msdn a las funciones de manejos de cadena de VB


no tengo conocimiento del manejo de cadenas de texto, podrías ayudarme de manera mas especifica por favor amigo, donde iria "MID" o "RIGHT"

gracias por la ayuda

engel lex

Cita de: rapbyone en  3 Julio 2014, 19:35 PM
no tengo conocimiento del manejo de cadenas de texto, podrías ayudarme de manera mas especifica por favor amigo, donde iria "MID" o "RIGHT"

ves la referencia, buscas la funcion cual descripcion te parezca apropiada (ya te dije cuales eran, te adelanté ese paso), haces click en ella, buscas la version de la funcion que se adapte a lo que quieres, haces click...

allí tienes ejemplos... aunque sea revisa el link, que te lo di, me dices
Citarpodría seleccionar que mostrar en el msgbox, pero no tengo claridad del como
me dan una mano amigos por favor
sin embargo no haces el esfuerzo por aprender... y este foro es para eso... por eso te pasé una referencia...
El problema con la sociedad actualmente radica en que todos creen que tienen el derecho de tener una opinión, y que esa opinión sea validada por todos, cuando lo correcto es que todos tengan derecho a una opinión, siempre y cuando esa opinión pueda ser ignorada, cuestionada, e incluso ser sujeta a burla, particularmente cuando no tiene sentido alguno.

79137913

HOLA!!!

Perdon por llegar tarde  ;D

Pero aca tenes una funcion completisima para obtener la ip externa, copia y pega el texto en un form vacio y voila, tu ip.

Esta funcion busca en varias webs tu posible ip externo y verifica que sea un ip valido.

Código (vb) [Seleccionar]
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
Public Function Gurl(sURL As String) As String
    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 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
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()
    Show
    Print CheckExternalIp
End Sub


GRACIAS POR LEER!!!
"Como no se puede igualar a Dios, ya he decidido que hacer, ¡SUPERARLO!"
"La peor de las ignorancias es no saber corregirlas"

79137913                          *Shadow Scouts Team*

rapbyone

Cita de: 79137913 en  3 Julio 2014, 20:32 PM
HOLA!!!

Perdon por llegar tarde  ;D

Pero aca tenes una funcion completisima para obtener la ip externa, copia y pega el texto en un form vacio y voila, tu ip.

Esta funcion busca en varias webs tu posible ip externo y verifica que sea un ip valido.

Código (vb) [Seleccionar]
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
Public Function Gurl(sURL As String) As String
    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 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
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()
    Show
    Print CheckExternalIp
End Sub


GRACIAS POR LEER!!!

Perfecto, gracias amigo :D