Diese Funktion ermittelt die MAC Adresse der Netzwerkkarte der übergebenen IP. Genutzt wird das Address Resolution Protocol.
benötigte Namespaces:
System.Runtime.InteropServices
System.Net
[DllImport("iphlpapi.dll")]
public static extern int SendARP(int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen);
/// <summary>
/// Requests the MAC address using Address Resolution Protocol
/// </summary>
/// <param name="IP">The IP.</param>
/// <returns>the MAC address</returns>
private string RequestMACAddress(string IP)
{
IPAddress addr = IPAddress.Parse(IP);
byte[] mac = new byte[6];
int length = mac.Length;
SendARP((int)addr.Address, 0, mac, ref length);
string macAddress = BitConverter.ToString(mac, 0, length);
return macAddress;
}
1 Kommentare zum Snippet