Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)Declare Function gethostbyname& Lib "wsock32.dll" (ByVal hostname$)Private Const SOCKET_ERROR = -1Type Hostent h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End TypeDim Hostent As Hostent, PointerToPointer As Long, ListAddress As Long Public Function vbGetHostByName(Optional strHostName As String = "www.csdn.net") Dim szString As String Dim sMsg As String szString = String(64, &H0) strHostName = strHostName + Mid(szString, Len(szString) - 64 + Len(strHostName), 64 - Len(strHostName)) If gethostbyname(strHostName) = SOCKET_ERROR Then ' If WSock32 error, then tell me about it sMsg = "Winsock Error" & Str$(WSAGetLastError()) MsgBox sMsg, vbOKOnly, "Administrator" Else PointerToPointer = gethostbyname(strHostName) ' Get the pointer to the address of the winsock hostent structure CopyMemory Hostent.h_name, ByVal _ PointerToPointer, Len(Hostent) ' Copy Winsock structure to the VisualBasic structure ListAddress = Hostent.h_addr_list ' Get the ListAddress of the Address List CopyMemory ListAddr, ByVal ListAddress, 4 ' Copy Winsock structure to the VisualBasic structure CopyMemory IPLong, ByVal ListAddr, 4 ' Get the first list entry from the Address List CopyMemory Addr, ByVal ListAddr, 4 'Label3.Caption = Trim$(CStr(Asc(IPLong.Byte4)) + "." + CStr(Asc(IPLong.Byte3)) _ + "." + CStr(Asc(IPLong.Byte2)) + "." + CStr(Asc(IPLong.Byte1))) End IfEnd Function
h_name As Long
h_aliases As Long
h_addrtype As Integer
h_length As Integer
h_addr_list As Long
End TypeDim Hostent As Hostent, PointerToPointer As Long, ListAddress As Long
Public Function vbGetHostByName(Optional strHostName As String = "www.csdn.net") Dim szString As String
Dim sMsg As String szString = String(64, &H0)
strHostName = strHostName + Mid(szString, Len(szString) - 64 + Len(strHostName), 64 - Len(strHostName)) If gethostbyname(strHostName) = SOCKET_ERROR Then ' If WSock32 error, then tell me about it
sMsg = "Winsock Error" & Str$(WSAGetLastError())
MsgBox sMsg, vbOKOnly, "Administrator"
Else
PointerToPointer = gethostbyname(strHostName) ' Get the pointer to the address of the winsock hostent structure
CopyMemory Hostent.h_name, ByVal _
PointerToPointer, Len(Hostent) ' Copy Winsock structure to the VisualBasic structure ListAddress = Hostent.h_addr_list ' Get the ListAddress of the Address List
CopyMemory ListAddr, ByVal ListAddress, 4 ' Copy Winsock structure to the VisualBasic structure
CopyMemory IPLong, ByVal ListAddr, 4 ' Get the first list entry from the Address List
CopyMemory Addr, ByVal ListAddr, 4 'Label3.Caption = Trim$(CStr(Asc(IPLong.Byte4)) + "." + CStr(Asc(IPLong.Byte3)) _
+ "." + CStr(Asc(IPLong.Byte2)) + "." + CStr(Asc(IPLong.Byte1)))
End IfEnd Function