Saber ip de conexion a internet de mi computador

Iniciado por hunter18, 23 Agosto 2010, 06:58 AM

0 Miembros y 2 Visitantes están viendo este tema.

Petro_Boca

#10
Cita de: _katze_ en 23 Agosto 2010, 20:48 PM
Cita de: xkiz en 23 Agosto 2010, 20:11 PM
Código (vb) [Seleccionar]

Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Const sURL = "http://checkip.dyndns.org/"

Private Declare Function InternetOpen Lib "wininet" 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 InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long

Public Function GetPublicIp()
Dim pIP() As String
Dim nose As String
   Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
   sBuffer = Space(108)
   hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
   hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
   InternetReadFile hFile, sBuffer, 108, Ret
   
   InternetCloseHandle hFile
   InternetCloseHandle hOpen
   
   pIP = Split(Trim(sBuffer), ": ")
   nose = Left(pIP(1), Len(pIP(1)) - 16)
   GetPublicIp = nose
End Function

Private Sub Main()
Debug.Print GetPublicIp
End Sub



modificando el buffer a como esta y lo q esta en verde ! tmb funcio esto es valido tmb o hay algo en especial el valor que se asigno en tu code original xkiz?
muy bueno y bien practico ::) ::) ::)

asi :D

pone 1 boton

Código (vb) [Seleccionar]

Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Const sURL = "http://checkip.dyndns.org/"

Private Declare Function InternetOpen Lib "wininet" 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 InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long

Public Function GetPublicIp()
Dim pIP() As String
Dim nose As String
    Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
    sBuffer = Space(108)
    hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
    hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    InternetReadFile hFile, sBuffer, 108, Ret

    InternetCloseHandle hFile
    InternetCloseHandle hOpen

    pIP = Split(Trim(sBuffer), ": ")
    nose = Left(pIP(1), Len(pIP(1)) - 16)
    GetPublicIp = nose
End Function




Private Sub Command1_Click()
MsgBox GetPublicIp
End Sub


_katze_

con minimo 108 anda bien xkiz asi no c ocupa mas del sizebuffer ! pero por las dudas hay como esta esta bn ! gracias por responder

Petro_Boca

Cita de: _katze_ en 24 Agosto 2010, 03:41 AM
con minimo 108 anda bien xkiz asi no c ocupa mas del sizebuffer ! pero por las dudas hay como esta esta bn ! gracias por responder

fijate q modifique mi mensaje...

Cita de: petro_boca en 24 Agosto 2010, 03:39 AM
Cita de: _katze_ en 23 Agosto 2010, 20:48 PM
Cita de: xkiz en 23 Agosto 2010, 20:11 PM
Código (vb) [Seleccionar]

Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Const sURL = "http://checkip.dyndns.org/"

Private Declare Function InternetOpen Lib "wininet" 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 InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long

Public Function GetPublicIp()
Dim pIP() As String
Dim nose As String
    Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
    sBuffer = Space(108)
    hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
    hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    InternetReadFile hFile, sBuffer, 108, Ret
   
    InternetCloseHandle hFile
    InternetCloseHandle hOpen
   
    pIP = Split(Trim(sBuffer), ": ")
    nose = Left(pIP(1), Len(pIP(1)) - 16)
    GetPublicIp = nose
End Function

Private Sub Main()
Debug.Print GetPublicIp
End Sub



modificando el buffer a como esta y lo q esta en verde ! tmb funcio esto es valido tmb o hay algo en especial el valor que se asigno en tu code original xkiz?
muy bueno y bien practico ::) ::) ::)

asi :D

pone 1 boton

Código (vb) [Seleccionar]

Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Const sURL = "http://checkip.dyndns.org/"

Private Declare Function InternetOpen Lib "wininet" 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 InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long

Public Function GetPublicIp()
Dim pIP() As String
Dim nose As String
    Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
    sBuffer = Space(108)
    hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
    hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    InternetReadFile hFile, sBuffer, 108, Ret

    InternetCloseHandle hFile
    InternetCloseHandle hOpen

    pIP = Split(Trim(sBuffer), ": ")
    nose = Left(pIP(1), Len(pIP(1)) - 16)
    GetPublicIp = nose
End Function




Private Sub Command1_Click()
MsgBox GetPublicIp
End Sub



_katze_

no dije como usarlo man, pero gracias igual !solo acote lo del code!