Newsgroup: it.comp.lang.visual-basic
Titolo: Acquisizione di un IP

salve a tutto l'NG
Ho un piccolissimo problema, devo riuscire ad acquisire l'indirizzo IP che
viene assegnato ogni volta che ci si collega ad internet.
Ringrazio Tutti
Ciriciao

 viene assegnato ogni volta che ci si collega ad internet.
La via più lunga:
[Da un esempio che avevo postato tempo fa]
'---------------------------------------------------------------------
'IP assegnato alla connessione corrente - Winsock
'---------------------------------------------------------------------
Public Const WS_VERSION_REQD = &H101
Public Const SOCKET_ERROR = -1
Public Const WSADescription_Len = 256
Public Const WSASYS_Status_Len = 128
Public Type HOSTENT
    hName As Long
    hAliases As Long
    hAddrType As Integer
    hLength As Integer
    hAddrList As Long
End Type
Public Type WSADATA
    wversion As Integer
    wHighVersion As Integer
    szDescription(0 To WSADescription_Len) As Byte
    szSystemStatus(0 To WSASYS_Status_Len) As Byte
    iMaxSockets As Integer
    iMaxUdpDg As Integer
    lpszVendorInfo As Long
End Type
Public Declare Function WSAGetLastError Lib "WSOCK32.DLL" () As Long
Public Declare Function WSAStartup Lib "WSOCK32.DLL" _
        (ByVal wVersionRequired As Long, _
        lpWSAData As WSADATA) As Long
Public Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
Public Declare Function gethostname Lib "WSOCK32.DLL" _
        (ByVal hostname As String, HostLen As Long) As Long
Public Declare Function gethostbyname Lib "WSOCK32.DLL" _
        (ByVal hostname As String) As Long
Public Declare Sub CopyMemoryLong Lib "kernel32" Alias _
        "RtlMoveMemory" (hpvDest As Any, _
        ByVal hpvSource As Long, _
        ByVal cbCopy As Long)
'La funzione restituisce l'IP Address assegnato alla macchina
'La gestione degli errori devi contruirla
Public Function IPAddress() as String
Dim hostname As String * 256
Dim hostent_addr As Long
Dim host As HOSTENT
Dim WSAD As WSADATA
Dim hostip_addr As Long
Dim arr_IPAddress() As Byte
Dim lpszIPAddress As String
Dim Counter As Integer
Dim lngRet as Long
  lngRet = WSAStartup(WS_VERSION_REQD, WSAD)
  If lngRet <> 0 then
      'Errore
  End If
  If gethostname(hostname, 256) = SOCKET_ERROR Then
     'Errore
  Else
    hostname = Trim$(hostname)
  End If
  hostent_addr = gethostbyname(hostname)
  If hostent_addr = 0 Then
    'Errore
  End If
  CopyMemoryLong host, hostent_addr, LenB(host)
  CopyMemoryLong hostip_addr, host.hAddrList, 4
  ReDim arr_IPAddress(1 To host.hLength)
  CopyMemoryLong arr_IPAddress(1), hostip_addr, host.hLength
  For Counter = 1 To host.hLength
    lpszIPAddress = lpszIPAddress & arr_IPAddress(Counter) & "."
  Next Counter
  IPAddress = Mid$(lpszIPAddress, 1, Len(lpszIPAddress) - 1)
  lngRet = WSACleanup()
  If lngRet <> 0 then
      'Errore
  End If
End Function
'---------------------------------------------------------------------
'Determina il tipo di connessione corrente
'---------------------------------------------------------------------
Public Const INTERNET_CONNECTION_MODEM = 1
Public Const INTERNET_CONNECTION_LAN = 2
Public Const INTERNET_CONNECTION_PROXY = 4
Public Const INTERNET_CONNECTION_MODEM_BUSY = 8
Public Declare Function InternetGetConnectedState _
        Lib "wininet.dll" ( _
        lpdwFlags As Long, _
        ByVal dwReserved As Long) As Long
Public Function GetConnectionType() as String
Dim lngFlags As Long
Dim lngRet As Long
    lngRet = InternetGetConnectedState(lngFlags, 0&)
    If lngFlags And INTERNET_CONNECTION_MODEM Then
        GetConnectionType = "Modem"
        If lngFlags And INTERNET_CONNECTION_MODEM_BUSY Then
            GetConnectionType = "Modem (Busy)"
        End If
    ElseIf lngFlags And INTERNET_CONNECTION_LAN Then
        GetConnectionType = "LAN"
    ElseIf lngFlags And INTERNET_CONNECTION_PROXY Then
        GetConnectionType = "Proxy Server"
    End If
End Function

Ciriciao
Beh la via più rapida è quella di inserire un controllo activex winsock
Per conoscere l'ip corrente basta controllare la proprietà "LocalIp".
Poi se t'interessa c'è anche una via più lunga usando l'api.
Ciao
Andrea Fontana
E-Mail: 
fon...@ubi1k-vb.net
ICQ Uin: 27799781