我想获取运行我的应用程序的电脑上蓝牙设备的 MAC 地址。
我已经尝试过以下方法:
private void GetMacAddress()
{
string macAddresses = "";
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up)
{
macAddresses += nic.GetPhysicalAddress().ToString();
Console.WriteLine(macAddresses);
}
}
}
但输出与命令提示符中的“ipconfig /all”不匹配。它不会打印我的蓝牙 MAC 地址。
有什么解决办法吗?
我已准备好解析从“ipconfig /all”获得的输出,但如何获取字符串形式的输出?
public static PhysicalAddress GetBTMacAddress() {
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) {
// Only consider Bluetooth network interfaces
if (nic.NetworkInterfaceType != NetworkInterfaceType.FastEthernetFx &&
nic.NetworkInterfaceType != NetworkInterfaceType.Wireless80211){
return nic.GetPhysicalAddress();
}
}
return null;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)