1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
List<string> list = new List<string>();
foreach (NetworkInterface adapter in nics)
{
if (adapter.OperationalStatus == OperationalStatus.Up)
{
PhysicalAddress address = adapter.GetPhysicalAddress();
byte[] bytes = address.GetAddressBytes();
string add = "";
for (int i = 0; i < bytes.Length; i++)
{
add += bytes[i].ToString("X2");
if (i != bytes.Length - 1)
{
add += "-";
}
}
if (!add.Equals(""))
list.Add(add);
}
}
return list; |