简单的办法是在控制台输入ping 目标IP,然后用 arp -a 来查看.
或者下面的代码(记下来以备后用):
Private
Declare
Function inet_addr()
Function inet_addr Lib "wsock32.dll" (ByVal s As String) As Int32
Private Declare Function SendARP()Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As Int32, ByVal SrcIP As Int32, ByRef pMacAddr As Int64, ByRef PhyAddrLen As Int32) As Int32
Public Function GetMac()Function GetMac(ByVal ip As String) As String
Dim mac As Int64
SendARP(inet_addr(ip), 0, mac, 16)
Dim b As Byte() = BitConverter.GetBytes(mac)
Dim strMac As String = ""
For i As Integer = 0 To 5
strMac &= "-" & String.Format("{0:X2}", b(i))
Next
Return strMac.Substring(1)
End Function
Private Declare Function SendARP()Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As Int32, ByVal SrcIP As Int32, ByRef pMacAddr As Int64, ByRef PhyAddrLen As Int32) As Int32
Public Function GetMac()Function GetMac(ByVal ip As String) As String
Dim mac As Int64
SendARP(inet_addr(ip), 0, mac, 16)
Dim b As Byte() = BitConverter.GetBytes(mac)
Dim strMac As String = ""
For i As Integer = 0 To 5
strMac &= "-" & String.Format("{0:X2}", b(i))
Next
Return strMac.Substring(1)
End Function