Type Inet_address
Byte4 As String * 1
Byte3 As String * 1
Byte2 As String * 1
Byte1 As String * 1
End Type
Public IPLong As Inet_address
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
Declare Function gethostbyname& Lib "wsock32.dll" (ByVal hostname$)
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As _ Any, hpvSource As Any, ByVal cbCopy As Long)
在Form中:
dim PointerToPointer As Long
dim ListAddress As Long
Dim Addr As Long
If gethostbyname("www.sohu.com") = SOCKET_ERROR Then
MsgBox "未找到此地址,请检查网络是否已经连通.", vbOKOnly, "错误"
Else
PointerToPointer = gethostbyname("www.sohu.com")
CopyMemory Hostent.h_name, ByVal _
PointerToPointer, Len(Hostent)
利用以下代码:(在窗体中放入一个按钮(NAME:CMDCONNECT)和一个WINSOCK控件)
Option Explicit
Const EchoPort = 80
Private Sub cmdConnect_Click()
Dim temp As String
temp = InputBox$("Enter a server name...", _
"Connect to the Echo Service", Winsock1.RemoteHost)
If temp <> "" Then
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.RemoteHost = temp
Winsock1.RemotePort = EchoPort
Winsock1.LocalPort = 0
Winsock1.Connect
End If
End Sub
Private Sub Winsock1_Connect()
MsgBox Winsock1.RemoteHostIP
End Sub
运行一下看,发现了什么!!!