How do I obtain the physical (MAC) address of an IP address using C#?

后端 未结 4 1405
失恋的感觉
失恋的感觉 2020-12-05 20:03

From C#, I want to do the equivalent of the following:

arp -a |findstr 192.168.1.254

Alternatively, the answer could call the SendARP funct

4条回答
  •  长情又很酷
    2020-12-05 20:41

    To find your own:

    Add a reference to System.Management

    ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
    
    ManagementObjectCollection mcCol = mc.GetInstances();
    
    foreach (ManagementObject mcObj in mcCol)
    {
      Console.WriteLine(mcObj["Caption"].ToString());
      Console.WriteLine(mcObj["MacAddress"].ToString());
    }
    

    Not sure about finding that of another device.

提交回复
热议问题