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 6333011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:22:49+00:00 2026-05-24T18:22:49+00:00

I have seen plenty of great C# examples which demonstrate how to convert IPv4

  • 0

I have seen plenty of great C# examples which demonstrate how to convert IPv4 addresses provided in CIDR notation (e.g. 192.168.0.1/25) into their relevant ranges (192.168.0.1 – 192.168.0.126). My program needs to be able to do this (to compute all the addresses within my local subnet) but I want to also support IPv6.

If my C# program has all of my typical ipconfig information (IPv4 address, subnet mask, IPv6 address, link-local v6 address, default gateway) – how would I go about generating a list of all of the IPv6 addresses in my local subnet and outputting them to the console?

  • 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-05-24T18:22:50+00:00Added an answer on May 24, 2026 at 6:22 pm

    You can use the eExNetworkLibrary.IP.IPAddressAnalysis class from the eExNetworkLibrary.

    The following code works with IPv4 and IPv6 (just tested).

            string strIn = "2001:DB8::/120";
    
            //Split the string in parts for address and prefix
            string strAddress = strIn.Substring(0, strIn.IndexOf('/'));
            string strPrefix = strIn.Substring(strIn.IndexOf('/') + 1);
    
            int iPrefix = Int32.Parse(strPrefix);
            IPAddress ipAddress = IPAddress.Parse(strAddress);
    
            //Convert the prefix length to a valid SubnetMask
    
            int iMaskLength = 32;
    
            if(ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
            {
                iMaskLength = 128;
            }
    
            BitArray btArray = new BitArray(iMaskLength);
            for (int iC1 = 0; iC1 < iMaskLength; iC1++)
            {
                //Index calculation is a bit strange, since you have to make your mind about byte order.
                int iIndex = (int)((iMaskLength - iC1 - 1) / 8) * 8 + (iC1 % 8);
    
                if (iC1 < (iMaskLength - iPrefix))
                {
                    btArray.Set(iIndex, false);
                }
                else
                {
                    btArray.Set(iIndex, true);
                }
            }
    
            byte[] bMaskData = new byte[iMaskLength / 8];
    
            btArray.CopyTo(bMaskData, 0);
    
            //Create subnetmask
            Subnetmask smMask = new Subnetmask(bMaskData);
    
            //Get the IP range
            IPAddress ipaStart = IPAddressAnalysis.GetClasslessNetworkAddress(ipAddress, smMask);
            IPAddress ipaEnd = IPAddressAnalysis.GetClasslessBroadcastAddress(ipAddress, smMask);
    
            //Omit the following lines if your network range is large
            IPAddress[] ipaRange = IPAddressAnalysis.GetIPRange(ipaStart, ipaEnd);
    
            //Debug output
            foreach (IPAddress ipa in ipaRange)
            {
                Console.WriteLine(ipa.ToString());
            }
    
            Console.ReadLine();
    

    I’m not completely sure if I have done the conversion from the prefix length to a byte array containing the subnet mask right, but this code should give you a good starting point.

    Edit: Updated the bit-bending part of the code. May be ugly, but works for this example. I think you will be capable of finding a better solution, if you need to. Those BitArrays are a pain in the neck.

    Be aware that generating an IPv6 network range can be a very memory/cpu exhausting task if the network is large.

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

Sidebar

Related Questions

I have seen plenty of discussion regarding the fastest way to select a first
I've seen plenty of examples around the internet on how to add a button
I've seen plenty of sites that provide data on which browsers and versions of
I have seen plenty of articles and SO questions about streaming TO an iPhone
I have seen plenty on how to fetch dictionaries and things from plists but
I have seen plenty of answers regarding how to remove leading and/or trailing zeros,
I have seen plenty of people mention some of the cool new features in
I have seen plenty of ways to change the pagesize of a new blank
Git/Mercurial have been becoming more and more popular. I have seen plenty of articles
While Ive seen plenty of examples in PHP, can't seem to find one in

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.