01.
Imports
System.Net
02.
03.
Public
Class
SendARP
04.
Declare
Function
SendARP
Lib
"iphlpapi.dll"
(
ByVal
DestIP
As
UInt32,
ByVal
SrcIP
As
UInt32,
ByVal
pMacAddr
As
Byte
(),
ByRef
PhyAddrLen
As
Integer
)
As
Integer
05.
06.
Sub
New
()
07.
End
Sub
08.
09.
10.
11.
12.
13.
Public
Shared
Function
GetMacAddress(IPAddress
As
String
)
As
String
14.
15.
Dim
intAddress
As
Integer
= BitConverter.ToInt32(System.Net.IPAddress.Parse(IPAddress).GetAddressBytes(), 0)
16.
Dim
macAddr
As
Byte
() =
New
Byte
(5) {}
17.
Dim
macAddrLen
As
UInteger = CUInt(macAddr.Length)
18.
If
SendARP(intAddress, 0, macAddr, macAddrLen) <> 0
Then
19.
Throw
New
InvalidOperationException(
"SendARP failed."
)
20.
End
If
21.
Dim
str
As
String
() =
New
String
(
CInt
(macAddrLen) - 1) {}
22.
For
i
As
Integer
= 0
To
macAddrLen - 1
23.
str(i) = macAddr(i).ToString(
"x2"
).ToUpper()
24.
Next
25.
Return
String
.Join(
"-"
, str)
26.
End
Function
27.
End
Class