Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 7 Default Network Adapter

Tags:

c#

.net

Following is my code to get the default NIC in Windows XP, but the same code doesn't work in Windows 7. It's really confusing after reading MSDN. Any solution?

//----------------- Getting all the Nic's --------------------
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
    //------------ Getting properties of IPV4 ----------------
    IPInterfaceProperties ipProps = nic.GetIPProperties();

    //------------ Getting the Ip Properties -----------------
    if (ipProps.GetIPv4Properties() != null)
    {
        dic.Add(ipProps.GetIPv4Properties().Index, nic.Name);
    }

Error: The request protocol is not configured, or has no implementation.

like image 819
Wajahat Kareem Avatar asked Aug 07 '26 10:08

Wajahat Kareem


1 Answers

It means you are hitting interface without IPv4 support on it. Check for it with:

if (nic.Supports(NetworkInterfaceComponent.IPv4)) // means IPv4 support is present

See here for more.

like image 120
favoretti Avatar answered Aug 09 '26 22:08

favoretti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!