Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My application is developed in C#4.0
when i run NetworkInterface.GetAllNetworkInterfaces() to get the NetworkConnections
i am able to get this in Windows Xp computer's
like below
System IP Address: 192.168.34.211
System Subnet Mask: 255.255.248.0




but in the windows 7 it is giving lot of junk network connections :(
like below



System IP Address: fe80::181c:7e45:865e:cef0%11
System Subnet Mask: 0.0.0.0

System IP Address: 192.168.34.211
System Subnet Mask: 255.255.248.0

System IP Address: fe80::5efe:192.168.34.211%12
System Subnet Mask: 0.0.0.0

System IP Address: fe80::100:7f:fffe%13
System Subnet Mask: 0.0.0.0




please advise
what could be the reason ?
Posted

Do something like this to filter out the IPV6 addresses:

C#
foreach (UnicastIPAddressInformation address in  ipInterfaceProperties.UnicastAddresses)
{
    if (address.Address.AddressFamily == AddressFamily.InternetworkV4)
    {
         ipAddressInfoList.Add(new IPNetworkInterfaceInfo(address.Address, address.IPv4Mask));
    }
}


BTW, you could have easily found this on google.
 
Share this answer
 
Comments
arun_pk 7-Jul-11 10:40am    
thanks it worked
just a small correction if (address.Address.AddressFamily == AddressFamily.InterNetwork)
Those are IPV6 addresses (which could be considered to be junk by some).
 
Share this answer
 
Comments
arun_pk 7-Jul-11 10:12am    
foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
{


IPInterfaceProperties ipInterfaceProperties = networkInterface.GetIPProperties();
foreach (UnicastIPAddressInformation address in ipInterfaceProperties.UnicastAddresses)
{
ipAddressInfoList.Add(new IPNetworkInterfaceInfo(address.Address, address.IPv4Mask));
}


}

current code is like this how shall i handle to avoid those junk values
The other addresses it gives you are the IPv6 addresses as well as the IPv4 address.

Hope this helps
 
Share this answer
 
Comments
arun_pk 7-Jul-11 10:12am    
foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
{


IPInterfaceProperties ipInterfaceProperties = networkInterface.GetIPProperties();
foreach (UnicastIPAddressInformation address in ipInterfaceProperties.UnicastAddresses)
{
ipAddressInfoList.Add(new IPNetworkInterfaceInfo(address.Address, address.IPv4Mask));
}


}

current code is like this how shall i handle to avoid those junk values

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900