I have following simple (trivial) method in C#, which should return MAC Address of selected network interface card (NIC):
public byte[] GetMacAddress(int adapterIndex)
{
NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
if ((adapterIndex >= networkInterfaces.Length) || (adapterIndex < 0))
{
return new byte[6] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
}
else
{
return networkInterfaces[adapterIndex].GetPhysicalAddress().GetAddressBytes();
} // if
} // GetMacAddress
Now, method is called from Program.cs (it's main method):
using System;
using Comms.NwStack.IpLayer.IpGateway.Ndis;
namespace NDISTester
{
class Program
{
static void Main(string[] args)
{
TCP_AdapterList networkAdapters = new TCP_AdapterList();
Console.WriteLine(networkAdapters.GetName(0) +
" " +
networkAdapters.GetMacAddress(0).ToString());
Console.ReadKey();
} // Main
} // class
} // namespace
and here is the output:
Local Area Connection System.Byte[]
Why do I get empty MAC Address?