gpt4 book ai didi

c# - 在 C# 中如何查找内部设备的 mac 地址而不是路由器 mac 地址

转载 作者:太空狗 更新时间:2023-10-29 21:43:00 26 4
gpt4 key购买 nike

出于某些安全原因,我想获取网络上我的软件用户的 mac 地址。但是我可以通过以下方法获取路由器的mac地址。

public string GetMACAddress()
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
String sMacAddress = string.Empty;
foreach (NetworkInterface adapter in nics)
{
if (sMacAddress == String.Empty)// only return MAC Address from first card
{
IPInterfaceProperties properties = adapter.GetIPProperties();
sMacAddress = adapter.GetPhysicalAddress().ToString();
}
} return sMacAddress;
}

我需要在 Internet 上访问我的软件的系统的特定 mac 地址以及该路由器的内部设备。这可能通过 C# 实现吗?

最佳答案

这对我有用!

string macAddress = NetworkInterface
.GetAllNetworkInterfaces()
.Where( nic => nic.OperationalStatus == OperationalStatus.Up && nic.NetworkInterfaceType != NetworkInterfaceType.Loopback )
.Select( nic => nic.GetPhysicalAddress().ToString() )
.FirstOrDefault();

关于c# - 在 C# 中如何查找内部设备的 mac 地址而不是路由器 mac 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49107719/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com