如何识别主物理网卡的MAC地址?
我正在用 C# 开发窗口应用程序。我使用以下代码来获取 MAC 地址
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;
}
在上面的代码中,我没有获取主 LAN 卡的 MAC 地址。在我的计算机中,我创建了两个环回适配器 A 和 A 。 B. 我有一张物理 LAN 卡。现在我想获取主物理 LAN 卡的 MAC 地址,而不是 A 和 LAN 卡的 MAC 地址。 B. 如何做到这一点?您能给我提供任何可以解决上述问题的代码或链接吗?
I am developing window application in C#. I am 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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将条件更改为:
或使用:
Change the condition to:
Or use this:
我想如果您使用 localhost 作为目标 IP 地址,您可以使用此链接...
如何获取 Mac 地址
I guess you could use this link if you use localhost as the target IP address...
How to get the Mac address