发信人: abc00gh(什么都不懂) 
整理人: winsy(2003-01-18 20:59:53), 站内信件
 | 
 
 
试试:
 
 Public Function GetIPAddress(Optional sHost As String = "") As String
     Dim sHostName As String * 256
     Dim lpHost As Long
     Dim HOST As HOSTENT
     Dim dwIPAddr As Long
     Dim tmpIPAddr() As Byte
     Dim i As Integer
     Dim sIPAddr As String
     Dim werr As Long
     
     If Not SocketsInitialize Then
         GetIPAddress = ""
         Exit Function
     End If
     
     If sHost = "" Then
         If gethostname(sHostName, 256) = SOCKET_ERROR Then
             werr = WSAGetLastError()
             GetIPAddress = ""
             SocketsCleanup
             Exit Function
         End If
         sHostName = Trim$(sHostName)
     Else
         sHostName = Trim$(sHost) & Chr$(0)
     End If
     
     lpHost = gethostbyname(sHostName)
     If lpHost = 0 Then
         werr = WSAGetLastError()
         GetIPAddress = ""
         SocketsCleanup
         Exit Function
     End If
     CopyMemory HOST, lpHost, Len(HOST)
     CopyMemory dwIPAddr, HOST.hAddrList, 4
     ReDim tmpIPAddr(1 To HOST.hLen)
     CopyMemory tmpIPAddr(1), dwIPAddr, HOST.hLen
     
     For i = 1 To HOST.hLen
         sIPAddr = sIPAddr & tmpIPAddr(i) & "."
     Next
     
     GetIPAddress = Mid$(sIPAddr, 1, Len(sIPAddr) - 1)
     SocketsCleanup
 End Function
 
 
 【 在 silentcpu 的大作中提到:】
 :VB中的Winsock控件可以建立计算机间的通讯,可是需要指定IP地址,我想知道如何用比较简单的方法能检测到本机的局域网IP地址及其在Internet上的IP地址,请高手赐教
 :......
   | 
 
 
 |