开发者

How to identify the MAC address of primary physical lan card?

I am developing window application in C#. I a开发者_Go百科m using the following code to obtain the MAC address

private void Form1_Load(object sender, EventArgs e)
        {
            lbl1.Text = "Hi";

            string macAddresses = "";

            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (nic.OperationalStatus == OperationalStatus.Up)
                {
                    macAddresses += nic.GetPhysicalAddress().ToString();
                    break;
                }
            }
            lbl1.Text = macAddresses;

        }

In the above code I am not getting the MAC address of the primary lan card. In my computer I created two loopback adapters A & B. I have one physical Lan Card. Now I want to obtain the MAC address of the primary physical Lan Card instead of A & B. How to do this ? Can you please provide me any code or link through which I can resolve the above issue ?


Change the condition to:

 // instead of nic.OperationalStatus == OperationalStatus.Up
 nic.NetworkInterfaceType != NetworkInterfaceType.Loopback

Or use this:

    nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet || nic.NetworkInterfaceType  ==  etworkInterfaceType.FastEthernetFx || nic.NetworkInterfaceType ==              NetworkInterfaceType.FastEthernetT


I guess you could use this link if you use localhost as the target IP address...
How to get the Mac address

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜