Because of the way that the internet was designed and the way that the IP protocol works, you wouldn't be able to find a mac address of someone unless you were local to them. The post earlier about using ping and arp is correct. The mac address is put into the IP packet at the 2nd level of the OSI model, its a physical address... once you go out through a router the mac address of the reported packet is changed, and is changed each and every time.. think of the mac as a "Return" address. You send out a packet and it goes across the country, and goes through 5 routers, the mac address on the packet will change each and every time it goes through a router, where the IP address won't. It's a type of routing code that the routers use to identify where the packet came from and where to send a response to.
example
Machine A sends a packet to Machine B, and it passes through Firewall C and D. The packet does this:
Machine A sends the packet to firewall C, firwall C repackages the packet with its mac address and looks for the quickest route to machine B, it determines that firewall D is the closest to it, so it repackages the packet with its own mac address (since that is where D will send a response to if it cant get to machine B) and sends it on to D.. D does the exact same thing and sends the packet to B. Once Machine B receives the packet the entire process starts over again, the last mac address that is reported is for firewall D, but the IP points to Machine A, thats how it knows where to go.
using System.Management;
...
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
if((bool)mo["IPEnabled"] == true)
Console.WriteLine("MAC address\t{0}", mo["MacAddress"].ToString());
mo.Dispose();
}
}
获取网卡硬件地址
using System.Management;
...
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
if((bool)mo["IPEnabled"] == true)
Console.WriteLine("MAC address\t{0}", mo["MacAddress"].ToString());
mo.Dispose();
}
}