C# 使用LINQ检索具有IP地址的MAC地址
我想用IP地址检索MAC地址C# 使用LINQ检索具有IP地址的MAC地址,c#,linq,C#,Linq,我想用IP地址检索MAC地址 var nics = NetworkInterface.GetAllNetworkInterfaces() .Where(ipProp => ipProp.GetIPProperties().UnicastAddresses .Where(ip => ip.Address.ToString().Equals("192.168.1.111")) ); 我得到一个错误: “无法将类型'System.
var nics = NetworkInterface.GetAllNetworkInterfaces()
.Where(ipProp => ipProp.GetIPProperties().UnicastAddresses
.Where(ip => ip.Address.ToString().Equals("192.168.1.111"))
);
我得到一个错误:
“无法将类型'System.Collections.Generic.IEnumerable'隐式转换为'bool'”
我该如何解决这个问题?这里有什么问题吗?:)编辑:现在有了。哦,谢谢!如果要此行返回MAC地址而不是网络接口,可以吗?
NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces().Where(ipProp => ipProp.GetIPProperties().UnicastAddresses.FirstOrDefault(ip => ip.Address.ToString().Equals("YOUR_IP")) != null).FirstOrDefault();
if (networkInterface != null)
{
Console.WriteLine(networkInterface.GetPhysicalAddress());
}