Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ?1996-2003 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 NO_ERROR = 0Private Declare Function inet_addr Lib "wsock32.dll" _
(ByVal s As String) As LongPrivate Declare Function SendARP Lib "iphlpapi.dll" _
(ByVal DestIP As Long, _
ByVal SrcIP As Long, _
pMacAddr As Long, _
PhyAddrLen As Long) As LongPrivate Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(dst As Any, _
src As Any, _
ByVal bcount As Long)
Private Sub Form_Load() Text1.Text = "192.168.1.101"
Text2.Text = ""
Command1.Caption = "Get Remote Mac Address"
End Sub
Private Sub Command1_Click() Dim sRemoteMacAddress As String
If Len(Text1.Text) > 0 Then
If GetRemoteMACAddress(Text1.Text, sRemoteMacAddress) Then
Text2.Text = sRemoteMacAddress
Else
Text2.Text = "(SendARP call failed)"
End If
End IfEnd Sub
Private Function GetRemoteMACAddress(ByVal sRemoteIP As String, _
sRemoteMacAddress As String) As Boolean Dim dwRemoteIP As Long
Dim pMacAddr As Long
Dim bpMacAddr() As Byte
Dim PhyAddrLen As Long
Dim cnt As Long
Dim tmp As String
'convert the string IP into
'an unsigned long value containing
'a suitable binary representation
'of the Internet address given
dwRemoteIP = inet_addr(sRemoteIP)
If dwRemoteIP <> 0 Then
'set PhyAddrLen to 6
PhyAddrLen = 6
'retrieve the remote MAC address
If SendARP(dwRemoteIP, 0&, pMacAddr, PhyAddrLen) = NO_ERROR Then
If pMacAddr <> 0 And PhyAddrLen <> 0 Then
'returned value is a long pointer
'to the mac address, so copy data
'to a byte array
ReDim bpMacAddr(0 To PhyAddrLen - 1)
CopyMemory bpMacAddr(0), pMacAddr, ByVal PhyAddrLen
'loop through array to build string
For cnt = 0 To PhyAddrLen - 1
If bpMacAddr(cnt) = 0 Then
tmp = tmp & "00-"
Else
tmp = tmp & Hex$(bpMacAddr(cnt)) & "-"
End If
Next
'remove the trailing dash
'added above and return True
If Len(tmp) > 0 Then
sRemoteMacAddress = Left$(tmp, Len(tmp) - 1)
GetRemoteMACAddress = True
End If Exit Function
Else
GetRemoteMACAddress = False
End If
Else
GetRemoteMACAddress = False
End If 'SendARP
Else
GetRemoteMACAddress = False
End If 'dwRemoteIP
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ?1996-2003 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 NO_ERROR = 0Private Declare Function inet_addr Lib "wsock32.dll" _
(ByVal s As String) As LongPrivate Declare Function SendARP Lib "iphlpapi.dll" _
(ByVal DestIP As Long, _
ByVal SrcIP As Long, _
pMacAddr As Long, _
PhyAddrLen As Long) As LongPrivate Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(dst As Any, _
src As Any, _
ByVal bcount As Long)
Private Sub Form_Load() Text1.Text = "192.168.1.101"
Text2.Text = ""
Command1.Caption = "Get Remote Mac Address"
End Sub
Private Sub Command1_Click() Dim sRemoteMacAddress As String
If Len(Text1.Text) > 0 Then
If GetRemoteMACAddress(Text1.Text, sRemoteMacAddress) Then
Text2.Text = sRemoteMacAddress
Else
Text2.Text = "(SendARP call failed)"
End If
End IfEnd Sub
Private Function GetRemoteMACAddress(ByVal sRemoteIP As String, _
sRemoteMacAddress As String) As Boolean Dim dwRemoteIP As Long
Dim pMacAddr As Long
Dim bpMacAddr() As Byte
Dim PhyAddrLen As Long
Dim cnt As Long
Dim tmp As String
'convert the string IP into
'an unsigned long value containing
'a suitable binary representation
'of the Internet address given
dwRemoteIP = inet_addr(sRemoteIP)
If dwRemoteIP <> 0 Then
'set PhyAddrLen to 6
PhyAddrLen = 6
'retrieve the remote MAC address
If SendARP(dwRemoteIP, 0&, pMacAddr, PhyAddrLen) = NO_ERROR Then
If pMacAddr <> 0 And PhyAddrLen <> 0 Then
'returned value is a long pointer
'to the mac address, so copy data
'to a byte array
ReDim bpMacAddr(0 To PhyAddrLen - 1)
CopyMemory bpMacAddr(0), pMacAddr, ByVal PhyAddrLen
'loop through array to build string
For cnt = 0 To PhyAddrLen - 1
If bpMacAddr(cnt) = 0 Then
tmp = tmp & "00-"
Else
tmp = tmp & Hex$(bpMacAddr(cnt)) & "-"
End If
Next
'remove the trailing dash
'added above and return True
If Len(tmp) > 0 Then
sRemoteMacAddress = Left$(tmp, Len(tmp) - 1)
GetRemoteMACAddress = True
End If Exit Function
Else
GetRemoteMACAddress = False
End If
Else
GetRemoteMACAddress = False
End If 'SendARP
Else
GetRemoteMACAddress = False
End If 'dwRemoteIP
End Function
解决方案 »
- 菜鸟求助:获取类似文本框窗口中光标所在位置的字符串
- 下面代码在ACCESS2000版本中正常,在SQL版本中老是报错,请高手指点
- 大侠们帮俺找找vb里的数据库操作出现的问题啊,在线等
- 如何改变VB Combobox 下拉键头的颜色
- 帮忙看一下程序!谢啦
- 求救,怎样使用vb控件(DataGrid,DataList,DBlist)?
- 请教关于字符串问题?
- ***********richtext又有问题了,高手们帮帮忙吧!*************
- 在线等待--100分 如何用vb来做一个小程序 实现如下操作(操纵系统是win2000,c盘已经共享)1.打开指定路径下的一个文件夹 2.复制对方指定
- 有谁知道!!如果今天是1999/03/16 ,那么。36天后的年月日???####年##月##日??
- 请教各位大侠们,通用对话框如何保存文件????
- 请问在窗口中鼠标移动到控件所在位置时控件就会浮起,就是“后退”这种按钮,这控件叫什么名字,如何调出?
why?