Private Declare Function WSAStartup Lib "wsock32.dll" _
(ByVal wVersionRequested As Integer, _
lpWSAData As WSADATA) As Long
Private Declare Function gethostbyname Lib "wsock32.dll" _
(ByVal name As String) As Long
Private Declare Function inet_ntoa Lib "wsock32.dll" _
(ByVal inaddr As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal length As Long)
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" _
(ByVal lpString As Any) As Long
Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" _
(ByVal lpString1 As Any, _
ByVal lpString2 As Any) As Long
Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
Private Type WSADATA
wVersion As Integer
wHighVersion As Integer
szDescription As String * 257
szSystemStatus As String * 129
iMaxSockets As Long
iMaxUdpDg As Long
lpVendorInfo As Long
End Type
Private Type HOSTENT
h_name As Long
h_aliases As Long
h_addrtype As Integer
h_length As Integer
h_addr_list As Long
End Type
Private Const AF_INET = 2
Private Function GetIP(strHostName As String) As String
Dim sockinfo As WSADATA
Dim hostinfo As HOSTENT
Dim pHostinfo As Long
Dim pIPAddress As Long
Dim ipAddress As Long
Dim pIPString As Long
Dim ipString As String
Dim retval As Long
retval = WSAStartup(&H202, sockinfo)
If retval <> 0 Then
Exit Function
End If
pHostinfo = gethostbyname(strHostName)
If pHostinfo <> 0 Then
CopyMemory hostinfo, ByVal pHostinfo, Len(hostinfo)
If hostinfo.h_addrtype = AF_INET Then
CopyMemory pIPAddress, ByVal hostinfo.h_addr_list, 4
CopyMemory ipAddress, ByVal pIPAddress, 4
pIPString = inet_ntoa(ipAddress)
ipString = Space(lstrlen(pIPString))
retval = lstrcpy(ipString, pIPString)
GetIP = ipString
End If
End If