Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8344327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:20:08+00:00 2026-06-09T06:20:08+00:00

I’m coding an application that has to get the network adapters configuration on a

  • 0

I’m coding an application that has to get the network adapters configuration on a Windows 7 machine just like it’s done in the Windows network adapters configuration panel:

enter image description here

So far I can get pretty much all the information I need from NetworkInterface.GetAllNetworkInterfaces() EXCEPT the subnet prefix length.

I’m aware that it can be retrieved from the C++ struc PMIB_UNICASTIPADDRESS_TABLE via OnLinkPrefixLength but I’m trying to stay in .net.

I also took a look at the Win32_NetworkAdapterConfiguration WMI class but it only seems to return the IP v4 subnet mask.

I also know that some information (not the prefix length, as far as I know) are in the registry:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters\Interfaces\{CLSID}

I also used SysInternals ProcessMon to try to get anything usefull when saving the network adapter settings but found nothing…

So, is there any clean .NET way to get this value? (getting it from the registry wouldn’t be a problem)

EDIT: Gateways

This doesn’t concern the actual question, but for those who need to retrieve the entire network adapter IPv6 configuration, the IPInterfaceProperties.GatewayAdresses property only supports the IPv4 gateways. As mentionned in the answer comments below, the only way to get the entire info until .NET framework 4.5 is to call WMI.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:20:10+00:00Added an answer on June 9, 2026 at 6:20 am

    You can do so using Win32_NetworkAdapterConfiguration. You might have overlooked it.

    IPSubnet will return an array of strings. Use the second value.
    I didn’t have time to whip up some C# code, but I’m sure you can handle it. Using WBEMTEST, I pulled this:

    instance of Win32_NetworkAdapterConfiguration
    {
        Caption = "[00000010] Intel(R) 82579V Gigabit Network Connection";
        DatabasePath = "%SystemRoot%\\System32\\drivers\\etc";
        DefaultIPGateway = {"192.168.1.1"};
        Description = "Intel(R) 82579V Gigabit Network Connection";
        DHCPEnabled = TRUE;
        DHCPLeaseExpires = "20120808052416.000000-240";
        DHCPLeaseObtained = "20120807052416.000000-240";
        DHCPServer = "192.168.1.1";
        DNSDomainSuffixSearchOrder = {"*REDACTED*"};
        DNSEnabledForWINSResolution = FALSE;
        DNSHostName = "*REDACTED*";
        DNSServerSearchOrder = {"192.168.1.1"};
        DomainDNSRegistrationEnabled = FALSE;
        FullDNSRegistrationEnabled = TRUE;
        GatewayCostMetric = {0};
        Index = 10;
        InterfaceIndex = 12;
        IPAddress = {"192.168.1.100", "fe80::d53e:b369:629a:7f95"};
        IPConnectionMetric = 10;
        IPEnabled = TRUE;
        IPFilterSecurityEnabled = FALSE;
        IPSecPermitIPProtocols = {};
        IPSecPermitTCPPorts = {};
        IPSecPermitUDPPorts = {};
        IPSubnet = {"255.255.255.0", "64"};
        MACAddress = "*REDACTED*";
        ServiceName = "e1iexpress";
        SettingID = "{B102679F-36AD-4D80-9D3B-D18C7B8FBF24}";
        TcpipNetbiosOptions = 0;
        WINSEnableLMHostsLookup = TRUE;
        WINSScopeID = "";
    };
    

    IPSubnet[1] = IPv6 subnet;

    Edit: Here’s some code.

    StringBuilder sBuilder = new StringBuilder();
    ManagementObjectCollection objects = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration").Get();
    foreach (ManagementObject mObject in objects)
    {
        string description = (string)mObject["Description"];
        string[] addresses = (string[])mObject["IPAddress"];
        string[] subnets = (string[])mObject["IPSubnet"];
        if (addresses == null && subnets == null)
            continue;
        sBuilder.AppendLine(description);
        sBuilder.AppendLine(string.Empty.PadRight(description.Length,'-'));
        if (addresses != null)
        {
            sBuilder.Append("IPv4 Address: ");
            sBuilder.AppendLine(addresses[0]);
            if (addresses.Length > 1)
            {
                sBuilder.Append("IPv6 Address: ");
                sBuilder.AppendLine(addresses[1]);
            }
        }
        if (subnets != null)
        {
            sBuilder.Append("IPv4 Subnet:  ");
            sBuilder.AppendLine(subnets[0]);
            if (subnets.Length > 1)
            {
                sBuilder.Append("IPv6 Subnet:  ");
                sBuilder.AppendLine(subnets[1]);
            }
        }
        sBuilder.AppendLine();
        sBuilder.AppendLine();
    }
    string output = sBuilder.ToString().Trim();
    MessageBox.Show(output);
    

    and some output:

    Intel(R) 82579V Gigabit Network Connection
    ------------------------------------------
    IPv4 Address: 192.168.1.100
    IPv6 Address: fe80::d53e:b369:629a:7f95
    IPv4 Subnet:  255.255.255.0
    IPv6 Subnet:  64
    

    Edit: I’m just going to clarify in case somebody searches for this later. The second item isn’t always the IPv6 value. IPv4 can have multiple addresses and subnets. Use Integer.TryParse on the IPSubnet array value to make sure it’s an IPv6 subnet and/or use the last item.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.