如何获得指定IP的计算机名
如何获得指定IP的计算机名 问题点数:20、回复次数:14Top
1 楼liuyan4794(青牛)回复于 2004-08-03 10:34:09 得分 0
怎么没人回答啊?Top
2 楼zhuiguo(明日月)回复于 2004-08-03 10:47:12 得分 0
hostnameTop
3 楼liuyan4794(青牛)回复于 2004-08-03 11:05:43 得分 0
hostname怎么用?能获得局域网上气汤计算机的名字吗Top
4 楼starsoulxp(星魂)回复于 2004-08-03 11:07:22 得分 5
Winsock1.RemoteHost '远程计算机的名字
Winsock1.RemoteHostIP '远程计算机的ip
Winsock1.LocalHostName '本地计算机的主机名
Winsock1.RemotePort '远程计算机的端口
Winsock1.LocalIP '本地计算机的ip
Winsock1.LocalPort '本地计算机的端口Top
5 楼taocsdn(放飞心情)回复于 2004-08-03 11:09:44 得分 0
Winsock1.LocalIP '本地计算机的ip
Winsock1.LocalPort '本地计算机的端口
Top
6 楼liuyan4794(青牛)回复于 2004-08-03 12:12:02 得分 0
Winsock1.RemoteHost '远程计算机的名字
Winsock1.RemoteHostIP '远程计算机的ip
这样能行吗,我怎么试不出来Top
7 楼happytoy()回复于 2004-08-03 12:44:31 得分 5
要获得指定IP的计算机名称,首先,必须在两个计算机之间建立连接;比如:你在你的计算机上运行了一个监听程序,在你要获得计算机名的PC上运行了连接程序。当目的PC上的连接程序开始运行是,连接你的计算机的IP,你的计算机的监听程序就可以接收到连接请求,这时你就可以用Winsock1.RemoteHost '获得远程计算机的名字Top
8 楼hdhai9451(☆新人类☆)回复于 2004-08-03 12:45:57 得分 5
Winsock1.RemoteHost '远程计算机的名字
Winsock1.RemoteHostIP '远程计算机的ip
Winsock1.LocalHostName '本地计算机的主机名
Winsock1.RemotePort '远程计算机的端口
Winsock1.LocalIP '本地计算机的ip
Winsock1.LocalPort '本地计算机的端口
Top
9 楼liuyan4794(青牛)回复于 2004-08-03 12:49:10 得分 0
不可以进行连接,只通过本机获得对方的计算机名
如果双方用自己的程序通讯,获得计算机名会很简单的Top
10 楼happytoy()回复于 2004-08-03 13:09:03 得分 0
这样的话,那你只好找一本讲WINDOWS的书看看,或许会有帮助Top
11 楼happytoy()回复于 2004-08-03 13:11:03 得分 5
那你试试TELNET呢Top
12 楼liuyan4794(青牛)回复于 2004-08-03 13:17:18 得分 0
nbtstat -a ip
这个dos命令可以获得计算机名及其他信息,但这个命令对应的API函数不知道Top
13 楼liuyan4794(青牛)回复于 2004-08-03 13:24:02 得分 0
回复人: of123() ( ) 信誉:115 2004-8-3 13:15:48 得分: 20
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2004 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Const WSADescription_Len As Long = 256
Private Const WSASYS_Status_Len As Long = 128
Private Const WS_VERSION_REQD As Long = &H101
Private Const IP_SUCCESS As Long = 0
Private Const SOCKET_ERROR As Long = -1
Private Const AF_INET As Long = 2
Private Type WSADATA
wVersion As Integer
wHighVersion As Integer
szDescription(0 To WSADescription_Len) As Byte
szSystemStatus(0 To WSASYS_Status_Len) As Byte
imaxsockets As Integer
imaxudp As Integer
lpszvenderinfo As Long
End Type
Private Declare Function WSAStartup Lib "wsock32" _
(ByVal VersionReq As Long, _
WSADataReturn As WSADATA) As Long
Private Declare Function WSACleanup Lib "wsock32" () As Long
Private Declare Function inet_addr Lib "wsock32" _
(ByVal s As String) As Long
Private Declare Function gethostbyaddr Lib "wsock32" _
(haddr As Long, _
ByVal hnlen As Long, _
ByVal addrtype As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(xDest As Any, _
xSource As Any, _
ByVal nbytes As Long)
Private Declare Function lstrlen Lib "kernel32" _
Alias "lstrlenA" _
(lpString As Any) As Long
Private Sub Command1_Click()
Text2.Text = GetHostNameFromIP(Text1.Text)
End Sub
Private Function SocketsInitialize() As Boolean
Dim WSAD As WSADATA
SocketsInitialize = WSAStartup(WS_VERSION_REQD, WSAD) = IP_SUCCESS
End Function
Private Sub SocketsCleanup()
If WSACleanup() <> 0 Then
MsgBox "Windows Sockets error occurred in Cleanup.", vbExclamation
End If
End Sub
Private Function GetHostNameFromIP(ByVal sAddress As String) As String
Dim ptrHosent As Long
Dim hAddress As Long
Dim nbytes As Long
If SocketsInitialize() Then
'convert string address to long
hAddress = inet_addr(sAddress)
If hAddress <> SOCKET_ERROR Then
'obtain a pointer to the HOSTENT structure
'that contains the name and address
'corresponding to the given network address.
ptrHosent = gethostbyaddr(hAddress, 4, AF_INET)
If ptrHosent <> 0 Then
'convert address and
'get resolved hostname
CopyMemory ptrHosent, ByVal ptrHosent, 4
nbytes = lstrlen(ByVal ptrHosent)
If nbytes > 0 Then
sAddress = Space$(nbytes)
CopyMemory ByVal sAddress, ByVal ptrHosent, nbytes
GetHostNameFromIP = sAddress
End If
Else
MsgBox "Call to gethostbyaddr failed."
End If 'If ptrHosent
SocketsCleanup
Else
MsgBox "String passed is an invalid IP."
End If 'If hAddress
Else
MsgBox "Sockets failed to initialize."
End If 'If SocketsInitialize
End Function
Top
14 楼liuyan4794(青牛)回复于 2004-08-03 13:24:27 得分 0
谢谢大家的帮助!!Top




