Imports System.Net
Public Class SendARP
Declare Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As UInt32, ByVal SrcIP As UInt32, ByVal pMacAddr As Byte(), ByRef PhyAddrLen As Integer) As Integer
Sub New()
End Sub
'http://www.pinvoke.net/default.aspx/iphlpapi.sendarp
'Please do not use the IPAddress.Address property
'This API is now obsolete. --> http://msdn.microsoft.com/en-us/library/system.net.ipaddress.address.aspx
'to get the IP in Integer mode use
Public Shared Function GetMacAddress(IPAddress As String) As String
'Dim dst As IPAddress = System.Net.IPAddress.Parse(IPAddress)
Dim intAddress As Integer = BitConverter.ToInt32(System.Net.IPAddress.Parse(IPAddress).GetAddressBytes(), 0)
Dim macAddr As Byte() = New Byte(5) {}
Dim macAddrLen As UInteger = CUInt(macAddr.Length)
If SendARP(intAddress, 0, macAddr, macAddrLen) <> 0 Then
Throw New InvalidOperationException("SendARP failed.")
End If
Dim str As String() = New String(CInt(macAddrLen) - 1) {}
For i As Integer = 0 To macAddrLen - 1
str(i) = macAddr(i).ToString("x2").ToUpper()
Next
Return String.Join("-", str)
End Function
End Class