Reputation: 473
I am using this code to find all ip address from all interface:
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
{
if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
...
}
}
}
}
The problem is on some pc it show the ip 169.254.x.x
(i know this is the "default" ip address.. useless here.)
if i do ipconfig /all
i don't see this ip, but the real question is how can i avoid to show this ip?
Upvotes: 0
Views: 3021
Reputation: 180867
In this case it would seem like a good fit to use IsDnsEligible
to eliminate the auto ip addresses;
foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
{
if(!ip.IsDnsEligible)
continue;
if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
...
Upvotes: 3