简体   繁体   中英

Retrive MAC Address with IP Address by using LINQ

I want to retrieve the MAC Address with IP Address...

var nics = NetworkInterface.GetAllNetworkInterfaces()
    .Where(ipProp => ipProp.GetIPProperties().UnicastAddresses
                     .Where(ip => ip.Address.ToString().Equals("192.168.1.111"))
    );

I am getting an error:

"Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'bool'"

How do I fix this?

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());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM