您好,以下的程式給您參考,謝謝!
using System.Net.NetworkInformation;
IPGlobalProperties compProperties = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
foreach (var x in adapter.GetIPProperties().UnicastAddresses)
{
//adapter.GetPhysicalAddress() 是MAC Address
//x.Address.ToString() 是 IP Address IPv4 or IPv6
listBox1.Items.Add(adapter.GetPhysicalAddress() + "@" + x.Address.ToString());
if(x.Address.ToString() == "YourIPAddress"){
MessageBox.Show(adapter.GetPhysicalAddress().ToString());
}
}
}
亂馬客blog: http://www.dotblogs.com.tw/rainmaker/