求助,急急急.......

52694 2002-10-09 07:44:21
我想编个程序,输入域名后可查知其IP.
该如何实现?

...全文
50 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
52694 2002-10-10
  • 打赏
  • 举报
回复
还是不会,求求你说详细点好吗?

不过我是要通过域名来查IP的

不是计算机名

junwhj 2002-10-09
  • 打赏
  • 举报
回复
debug.print GetIP("计算名称")
52694 2002-10-09
  • 打赏
  • 举报
回复
但,怎样用上面的代码啊
junwhj 2002-10-09
  • 打赏
  • 举报
回复
说明:上面的程序是CSDN上以前的贴子中Copy出来的,不记得是哪个贴子了。
junwhj 2002-10-09
  • 打赏
  • 举报
回复
Option Explicit

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

retval = WSACleanup()
End Function

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧