### Install IPNetwork2 via NuGet Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/index.md Install the IPNetwork2 library using the NuGet package manager. ```shell nuget install IPNetwork2 ``` -------------------------------- ### Install IPNetwork CLI on Linux (Manual x64) Source: https://github.com/lduchosal/ipnetwork/blob/master/README.md Manually install the IPNetwork command-line interface for x64 Linux systems by downloading and extracting the archive to /usr/local/bin. ```bash # x64 curl -sL https://github.com/lduchosal/ipnetwork/releases/latest/download/ipnetwork-linux-x64.tar.gz | tar xz -C /usr/local/bin ``` -------------------------------- ### Install IPNetwork CLI on Linux (Manual ARM64) Source: https://github.com/lduchosal/ipnetwork/blob/master/README.md Manually install the IPNetwork command-line interface for ARM64 Linux systems by downloading and extracting the archive to /usr/local/bin. ```bash # ARM64 curl -sL https://github.com/lduchosal/ipnetwork/releases/latest/download/ipnetwork-linux-arm64.tar.gz | tar xz -C /usr/local/bin ``` -------------------------------- ### Install IPNetwork .NET Library via NuGet Source: https://github.com/lduchosal/ipnetwork/blob/master/README.md Install the IPNetwork2 .NET library using the NuGet package manager. ```csharp PM> nuget install IPNetwork2 ``` -------------------------------- ### Install IPNetwork CLI on Windows Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Use Chocolatey to install the IPNetwork CLI tool on Windows systems. ```powershell choco install ipnetwork ``` -------------------------------- ### Install IPNetwork CLI on macOS/Linux Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Use Homebrew to install the IPNetwork CLI tool on macOS or Linux systems. ```bash brew install lduchosal/ipnetwork/ipnetwork ``` -------------------------------- ### Display Network Information (JSON Output) Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Example of using the -j flag with the IPNetwork CLI to get network details in JSON format. ```bash $ ipnetwork -j 192.168.1.0/24 [ { "ipnetwork": "192.168.1.0/24", "network": "192.168.1.0", "netmask": "255.255.255.0", "cidr": 24, "broadcast": "192.168.1.255", "firstUsable": "192.168.1.1", "lastUsable": "192.168.1.254", "usable": "254", "total": "256" } ] ``` -------------------------------- ### List All IP Addresses in a Network Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Example of using the -x option to list all individual IP addresses within a specified network range. ```bash $ ipnetwork -x 10.0.0.0/30 10.0.0.0 10.0.0.1 10.0.0.2 10.0.0.3 ``` -------------------------------- ### Split Network into CIDR Subnets Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/index.md This example demonstrates splitting a larger network (10.0.0.0/8) into smaller subnets, each with a CIDR of 9. It displays the details for each resulting subnet. ```bash c:\> ipnetwork -s 9 10.0.0.0/8 ``` ```text IPNetwork : 10.0.0.0/9 Network : 10.0.0.0 Netmask : 255.128.0.0 Cidr : 9 Broadcast : 10.127.255.255 FirstUsable : 10.0.0.1 LastUsable : 10.127.255.254 Usable : 8388606 -- IPNetwork : 10.128.0.0/9 Network : 10.128.0.0 Netmask : 255.128.0.0 Cidr : 9 Broadcast : 10.255.255.255 FirstUsable : 10.128.0.1 LastUsable : 10.255.255.254 Usable : 8388606 ``` -------------------------------- ### C# IPNetwork Supernet Example Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Shows how to supernet an array of IPNetwork2 objects into the smallest possible common subnet using the Supernet method in C#. ```csharp IPNetwork2[] supernet = IPNetwork2.Supernet(new[] { IPNetwork2.Parse("192.168.0.0/24"), IPNetwork2.Parse("192.168.1.0/24") }); // supernet[0] = 192.168.0.0/23 ``` -------------------------------- ### Display Network Information (Default Output) Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Example of running the IPNetwork CLI without specific print options to display all network details in a human-readable format. ```bash $ ipnetwork 10.0.0.0/8 IPNetwork : 10.0.0.0/8 Network : 10.0.0.0 Netmask : 255.0.0.0 Cidr : 8 Broadcast : 10.255.255.255 FirstUsable : 10.0.0.1 LastUsable : 10.255.255.254 Usable : 16777214 Total : 16777216 ``` -------------------------------- ### Subnetting a Network Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/doc/README.html Demonstrates subnetting a large network (0.0.0.0/0) into a specified number of smaller subnets. Shows how to get the count and iterate through the resulting subnets. ```csharp IPNetwork2 wholeInternet = IPNetwork2.Parse("0.0.0.0/0"); byte newCidr = 2; IPNetworkCollection subneted = wholeInternet.Subnet(newCidr); Console.WriteLine("{0} was subnetted into {1} subnets", wholeInternet, subneted.Count); Console.WriteLine("First: {0}", subneted[0]); Console.WriteLine("Last : {0}", subneted[subneted.Count - 1]); Console.WriteLine("All :"); foreach (IPNetwork2 ipnetwork in subneted) { Console.WriteLine("{0}", ipnetwork); } ``` -------------------------------- ### Usable Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets the number of usable IP addresses in the Network. ```APIDOC ## Usable ### Description Gets the number of usable IP addresses in the Network. ### Property Value [BigInteger](https://learn.microsoft.com/dotnet/api/system.numerics.biginteger) ``` -------------------------------- ### C# IPNetwork Subnet Example Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Demonstrates splitting an IP network into smaller subnets with a specified CIDR prefix length using the Subnet method in C#. ```csharp IPNetworkCollection subnets = ipnetwork.Subnet(25); // subnets[0] = 192.168.168.0/25 // subnets[1] = 192.168.168.128/25 ``` -------------------------------- ### Supernet Networks into Smallest Subnets Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Example of using the -w option to supernet multiple networks into the smallest possible common subnets. ```bash $ ipnetwork -w 10.0.0.0/24 10.0.1.0/24 IPNetwork : 10.0.0.0/23 ... ``` -------------------------------- ### Select Specific Fields for Display Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Example of using specific print options (-n for network, -c for CIDR) to display only selected fields from the IPNetwork CLI. ```bash $ ipnetwork -n -c 10.0.0.0/8 Network : 10.0.0.0 Cidr : 8 ``` -------------------------------- ### Split Network into Subnets Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Example of using the -s option to split a given network into smaller subnets with a specified CIDR prefix length. ```bash $ ipnetwork -s 9 10.0.0.0/8 IPNetwork : 10.0.0.0/9 ... -- IPNetwork : 10.128.0.0/9 ... ``` -------------------------------- ### C# IPNetwork ParseRange Example Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Demonstrates converting an IP address range string into a minimal set of CIDR blocks using the ParseRange method in C#. ```csharp IEnumerable blocks = IPNetwork2.ParseRange("192.168.1.45 - 192.168.1.65"); // Converts IP range to minimal set of CIDR blocks ``` -------------------------------- ### Supernet Networks into Smallest Possible Subnets (Example 2) Source: https://github.com/lduchosal/ipnetwork/blob/master/README.md Demonstrates supernetting where the input networks remain separate, showing individual network details. This occurs when networks are not adjacent or cannot be combined into a smaller CIDR. ```bash c:\> ipnetwork -w 192.168.0.0/24 192.168.2.0/24 IPNetwork : 192.168.0.0/24 Network : 192.168.0.0 Netmask : 255.255.255.0 Cidr : 24 Broadcast : 192.168.0.255 FirstUsable : 192.168.0.1 LastUsable : 192.168.0.254 Usable : 254 -- IPNetwork : 192.168.2.0/24 Network : 192.168.2.0 Netmask : 255.255.255.0 Cidr : 24 Broadcast : 192.168.2.255 FirstUsable : 192.168.2.1 LastUsable : 192.168.2.254 Usable : 254 ``` -------------------------------- ### Total Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets the total number of IP addresses in the Network. ```APIDOC ## Total ### Description Gets the total number of IP addresses in the Network. ### Property Value [BigInteger](https://learn.microsoft.com/dotnet/api/system.numerics.biginteger) ``` -------------------------------- ### Supernet Networks into a Single Subnet Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Example of using the -W option to supernet multiple networks into a single, largest possible subnet. ```bash $ ipnetwork -W 10.0.0.0/24 10.0.10.0/24 IPNetwork : 10.0.0.0/23 ... ``` -------------------------------- ### FirstUsable Property Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets the first usable IP address within the network range. ```APIDOC ## FirstUsable Property ### Description Gets first usable IP adress in Network. ### Property Value - **FirstUsable** (IPAddress) - The first usable IP address in the network. ``` -------------------------------- ### Refresh Environment Command Source: https://github.com/lduchosal/ipnetwork/blob/master/chocolatey/README.md Use this command to refresh the environment variables after installation if the command is not found. ```powershell refreshenv ``` -------------------------------- ### Subtract Network from Other Networks Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Example of using the -S option to subtract one network from another, showing the resulting networks. ```bash $ ipnetwork -S 10.0.1.0/24 10.0.0.0/23 10.0.0.0/24 ``` -------------------------------- ### Print IPNetwork2 Instance Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Returns a string representation of the IPNetwork2 object. This method is used to get a clear, human-readable string of the network details. ```csharp public string Print() ``` -------------------------------- ### Test Network Containment Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Example of using the -C option to check if a given network contains other specified networks. ```bash $ ipnetwork -C 10.0.0.0/8 10.0.1.0/24 10.0.0.0/8 contains 10.0.1.0/24 : True ``` -------------------------------- ### Supernet Networks into One Single Subnet Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/index.md This example uses the -W flag to supernet two networks into the smallest possible single subnet that encompasses both. The output shows the resulting single /16 subnet. ```bash C:\>ipnetwork -W 192.168.0.0/24 192.168.129.0/24 ``` ```text IPNetwork : 192.168.0.0/16 Network : 192.168.0.0 Netmask : 255.255.0.0 Cidr : 16 Broadcast : 192.168.255.255 FirstUsable : 192.168.0.1 LastUsable : 192.168.255.254 Usable : 65534 ``` -------------------------------- ### Split Network and Display Only Network Address Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/index.md This example splits a network into /12 CIDR subnets and uses `grep -v --` to filter the output, displaying only the 'IPNetwork' lines for each resulting subnet. ```bash C:\>ipnetwork -i -s 12 10.0.0.0/8 | grep -v \-\- ``` ```text IPNetwork : 10.0.0.0/12 IPNetwork : 10.16.0.0/12 IPNetwork : 10.32.0.0/12 IPNetwork : 10.48.0.0/12 IPNetwork : 10.64.0.0/12 IPNetwork : 10.80.0.0/12 IPNetwork : 10.96.0.0/12 IPNetwork : 10.112.0.0/12 IPNetwork : 10.128.0.0/12 IPNetwork : 10.144.0.0/12 IPNetwork : 10.160.0.0/12 IPNetwork : 10.176.0.0/12 IPNetwork : 10.192.0.0/12 IPNetwork : 10.208.0.0/12 IPNetwork : 10.224.0.0/12 IPNetwork : 10.240.0.0/12 ``` -------------------------------- ### Supernet Networks into Smallest Possible Subnets (Example 1) Source: https://github.com/lduchosal/ipnetwork/blob/master/README.md Combines two adjacent /24 networks into a single /23 supernet. Displays the resulting supernet's details. ```bash C:\>ipnetwork -w 192.168.0.0/24 192.168.1.0/24 IPNetwork : 192.168.0.0/23 Network : 192.168.0.0 Netmask : 255.255.254.0 Cidr : 23 Broadcast : 192.168.1.255 FirstUsable : 192.168.0.1 LastUsable : 192.168.1.254 Usable : 510 ``` -------------------------------- ### C# IPNetwork Parse Example Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Demonstrates parsing an IP network string into an IPNetwork2 object in C#. Properties like Network, Netmask, Broadcast, Cidr, FirstUsable, LastUsable, Usable, and Total are accessible. ```csharp IPNetwork2 ipnetwork = IPNetwork2.Parse("192.168.168.100/24"); // Properties: .Network, .Netmask, .Broadcast, .Cidr, // .FirstUsable, .LastUsable, .Usable, .Total ``` -------------------------------- ### Test Network Overlap Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Example of using the -o option to check if a given network overlaps with other specified networks. ```bash $ ipnetwork -o 10.0.0.0/8 192.168.0.0/16 10.0.0.0/8 overlaps 192.168.0.0/16 : False ``` -------------------------------- ### Supernet Networks into One Single Subnet Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/index.html Example of supernetting two IPv4 networks into a single, larger subnet. ```bash C:\>ipnetwork -W 192.168.0.0/24 192.168.129.0/24 IPNetwork : 192.168.0.0/16 Network : 192.168.0.0 Netmask : 255.255.0.0 Cidr : 16 Broadcast : 192.168.255.255 FirstUsable : 192.168.0.1 LastUsable : 192.168.255.254 Usable : 65534 ``` -------------------------------- ### Supernet Networks into Smallest Possible Subnets (Non-Adjacent) Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/index.md This example demonstrates the behavior of the -w flag when networks are not adjacent. It lists the original networks separately, indicating that they were not supernetted into a single smaller subnet. ```bash c:\> ipnetwork -w 192.168.0.0/24 192.168.2.0/24 ``` ```text IPNetwork : 192.168.0.0/24 Network : 192.168.0.0 Netmask : 255.255.255.0 Cidr : 24 Broadcast : 192.168.0.255 FirstUsable : 192.168.0.1 LastUsable : 192.168.0.254 Usable : 254 -- IPNetwork : 192.168.2.0/24 Network : 192.168.2.0 Netmask : 255.255.255.0 Cidr : 24 Broadcast : 192.168.2.255 FirstUsable : 192.168.2.1 LastUsable : 192.168.2.254 Usable : 254 ``` -------------------------------- ### TryToBigInteger Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Converts an IPAddress to its BigInteger representation. For example, 0.0.0.0 becomes 0, and 0.0.1.0 becomes 256. ```APIDOC ## TryToBigInteger(IPAddress, out BigInteger?) ### Description Converts an IPAddress to its BigInteger representation. For example, 0.0.0.0 becomes 0, and 0.0.1.0 becomes 256. ### Method static bool TryToBigInteger(IPAddress ipaddress, out BigInteger? uintIpAddress) ### Parameters #### Path Parameters - `ipaddress` (IPAddress) - A string containing an ip address to convert. - `uintIpAddress` (BigInteger)? - A number representing the IPAdress. #### Returns - `bool` - true if ipaddress was converted successfully; otherwise, false. ``` -------------------------------- ### Remove IP and Regroup Networks Source: https://github.com/lduchosal/ipnetwork/blob/master/README.md This advanced example removes a specific IP address from a network, then uses a pipeline of commands to regroup the remaining IPs into the smallest possible networks. It demonstrates complex network manipulation using multiple CLI tools. ```bash C:\> ipnetwork -i -s 32 192.168.0.0/24 \ | grep -v \-\- \ | awk "{print $3;}" \ | grep -v 192.168.0.213/32 \ | xargs ipnetwork -i -w \ | grep -v \-\- IPNetwork : 192.168.0.224/27 IPNetwork : 192.168.0.216/29 IPNetwork : 192.168.0.214/31 IPNetwork : 192.168.0.212/32 IPNetwork : 192.168.0.208/30 IPNetwork : 192.168.0.192/28 IPNetwork : 192.168.0.128/26 IPNetwork : 192.168.0.0/25 ``` -------------------------------- ### ToBigInteger Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Converts an IPAddress to its BigInteger representation. For example, '0.0.0.0' becomes 0, and '0.0.1.0' becomes 256. ```APIDOC ## ToBigInteger ### Description Converts an IPAddress to its BigInteger representation. For example, '0.0.0.0' becomes 0, and '0.0.1.0' becomes 256. ### Method static BigInteger ToBigInteger(IPAddress ipaddress) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response - **BigInteger**: A number representing the IPAddress. ### Response Example None ``` -------------------------------- ### Supernet Networks into Smallest Possible Subnets (Adjacent) Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/index.md This example shows how the ipnetwork utility supernets two adjacent networks (192.168.0.0/24 and 192.168.1.0/24) into the smallest possible encompassing subnet, which is a /23 in this case. ```bash C:\>ipnetwork -w 192.168.0.0/24 192.168.1.0/24 ``` ```text IPNetwork : 192.168.0.0/23 Network : 192.168.0.0 Netmask : 255.255.254.0 Cidr : 23 Broadcast : 192.168.1.255 FirstUsable : 192.168.0.1 LastUsable : 192.168.1.254 Usable : 510 ``` -------------------------------- ### C# IPNetwork Subtract Example Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Illustrates subtracting one IP network from another using the Subtract method in C#, returning an IEnumerable of IPNetwork2 objects. ```csharp IEnumerable result = network1.Subtract(network2); ``` -------------------------------- ### Display IPNetwork Information Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/doc/README.html Shows how to display detailed information about an IPv4 network. Use this to get network address, netmask, CIDR, broadcast, and usable IP ranges. ```bash c:\\> ipnetwork 10.0.0.0/8 IPNetwork : 10.0.0.0/8 Network : 10.0.0.0 Netmask : 255.0.0.0 Cidr : 8 Broadcast : 10.255.255.255 FirstUsable : 10.0.0.1 LastUsable : 10.255.255.254 Usable : 16777214 ``` -------------------------------- ### C# IPNetwork Contains and Overlap Example Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Shows how to use the Contains and Overlap methods on an IPNetwork2 object in C# to check for IP address containment and network overlap. ```csharp bool contains = ipnetwork.Contains(IPAddress.Parse("192.168.168.1")); // true bool overlap = ipnetwork.Overlap(IPNetwork2.Parse("192.168.1.0/24")); // false ``` -------------------------------- ### Test if a Network Overlaps Another Network Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/index.md This example uses the -o flag to check for overlap between a /24 network (10.0.0.1/24) and two other networks (10.0.0.0/8 and 10.0.1.0/24). The output indicates 'True' for the first comparison and 'False' for the second. ```bash C:\>ipnetwork -o 10.0.0.1/24 10.0.0.0/8 10.0.1.0/24 ``` ```text 10.0.0.0/24 overlaps 10.0.0.0/8 : True 10.0.0.0/24 overlaps 10.0.1.0/24 : False ``` -------------------------------- ### WideSubnet(string, string) Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Finds the widest subnet that can contain both the start and end IP addresses. This is useful for creating a network range that encompasses a specific start and end point. ```APIDOC ## WideSubnet(string, string) ### Description Finds the widest subnet that can contain both the start and end IP addresses. ### Method static IPNetwork2 ### Parameters #### Path Parameters - **start** (string) - Required - The starting IP address. - **end** (string) - Required - The ending IP address. #### Exceptions - **ArgumentNullException**: Thrown when either the start or end IP address is null or empty. - **ArgumentException**: Thrown when the start or end IP addresses are not valid. - **NotSupportedException**: Thrown when the start and end IP addresses have different address families. ### Returns [IPNetwork2](System.Net.IPNetwork2.html) The widest subnet that contains both the start and end IP addresses. ``` -------------------------------- ### Netmask Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets the netmask of the IP network. ```APIDOC ## Netmask ### Description Gets the netmask of the IP network. ### Property Value [IPAddress](https://learn.microsoft.com/dotnet/api/system.net.ipaddress) ``` -------------------------------- ### ipnetwork Command-Line Usage and Options Source: https://github.com/lduchosal/ipnetwork/blob/master/README.md Displays the help message and available options for the ipnetwork command. Use this to understand the various flags for printing information, parsing options, and performing actions on networks. ```bash Provide at least one ipnetwork Usage: ipnetwork [-inmcbflu] [-d cidr|-D] [-h|-s cidr|-S|-w|-W|-x|-C network|-o network] networks .. Version: 3.2.0 Print options -i : network -n : network address -m : netmask -c : cidr -b : broadcast -f : first usable ip address -l : last usable ip address -u : number of usable ip addresses -t : total number of ip addresses Parse options -d cidr : use cidr if not provided (default /32) -D : IPv4 only - use default cidr (ClassA/8, ClassB/16, ClassC/24) Actions -h : help message -s cidr : split network into cidr subnets -w : supernet networks into smallest possible subnets -W : supernet networks into one single subnet -x : list all ipadresses in networks -C network : network contain networks -o network : network overlap networks -S network : substract network from subnet networks : one or more network addresses (1.2.3.4 10.0.0.0/8 10.0.0.0/255.0.0.0 2001:db8::/32 2001:db8:1:2:3:4:5:6/128 ) ``` -------------------------------- ### Network Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets the network address of the IP network. ```APIDOC ## Network ### Description Gets the network address of the IP network. ### Property Value [IPAddress](https://learn.microsoft.com/dotnet/api/system.net.ipaddress) ``` -------------------------------- ### IANA_CBLK_RESERVED1 Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets the IANA reserved IPNetwork 192.168.0.0/16. ```APIDOC ## IANA_CBLK_RESERVED1 ### Description Gets the IANA reserved IPNetwork 192.168.0.0/16. ### Property Value [IPNetwork2](System.Net.IPNetwork2.html) The IANA reserved IPNetwork 192.168.0.0/16. ``` -------------------------------- ### Value Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets or sets the string representation of the IPNetwork property. ```APIDOC ## Value ### Description Gets or sets the string representation of the IPNetwork property. ### Property Value [string](https://learn.microsoft.com/dotnet/api/system.string) Gets or sets a value indicating whether gets or sets the value of the IPNetwork property. ``` -------------------------------- ### Add IPNetwork .NET Library Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt Add the IPNetwork2 NuGet package to your .NET project using the dotnet CLI. ```bash dotnet add package IPNetwork2 ``` -------------------------------- ### LastUsable Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets the last usable IP address in the Network. ```APIDOC ## LastUsable ### Description Gets the last usable IP address in the Network. ### Property Value [IPAddress](https://learn.microsoft.com/dotnet/api/system.net.ipaddress) ``` -------------------------------- ### Broadcast Property Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets the broadcast IP address for the network. ```APIDOC ## Broadcast Property ### Description Gets broadcast address. ### Property Value - **Broadcast** (IPAddress) - The broadcast IP address. ``` -------------------------------- ### Cidr Property Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets the CIDR notation for the network's netmask. ```APIDOC ## Cidr Property ### Description Gets the CIDR netmask notation. ### Property Value - **Cidr** (byte) - The CIDR netmask notation. ``` -------------------------------- ### Supernetting IP Networks using Operator Overload Source: https://github.com/lduchosal/ipnetwork/blob/master/README.md Demonstrates combining IP networks using the '+' operator overload, which provides a more concise syntax for supernetting. Use this for a cleaner code representation of network aggregation. ```C# IPNetwork2 ipnetwork1 = IPNetwork2.Parse("192.168.0.0/24"); IPNetwork2 ipnetwork2 = IPNetwork2.Parse("192.168.1.0/24"); IPNetwork2[] ipnetwork3 = ipnetwork1 + ipnetwork2; Console.WriteLine("{0} + {1} = {2}", ipnetwork1, ipnetwork2, ipnetwork3[0]); ``` -------------------------------- ### IANA_BBLK_RESERVED1 Property Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets the IANA reserved IP network range 172.12.0.0/12. ```APIDOC ## IANA_BBLK_RESERVED1 Property ### Description Gets 172.12.0.0/12. ### Property Value - **IANA_BBLK_RESERVED1** (IPNetwork2) - The IANA reserved IPNetwork 172.12.0.0/12. ``` -------------------------------- ### IANA_ABLK_RESERVED1 Property Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets the IANA reserved IP network range 10.0.0.0/8. ```APIDOC ## IANA_ABLK_RESERVED1 Property ### Description Gets 10.0.0.0/8. ### Property Value - **IANA_ABLK_RESERVED1** (IPNetwork2) - The IANA reserved IPNetwork 10.0.0.0/8. ``` -------------------------------- ### IPNetwork Utility Command Line Usage Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/index.html Shows the general usage and options for the IPNetwork command-line utility. ```bash Provide at least one ipnetwork Usage: ipnetwork [-inmcbflu] [-d cidr|-D] [-h|-s cidr|-S|-w|-W|-x|-C network|-o network] networks ... Version: 3.1.0 Print options -i : network -n : network address -m : netmask -c : cidr -b : broadcast -f : first usable ip address -l : last usable ip address -u : number of usable ip addresses -t : total number of ip addresses Parse options -d cidr : use cidr if not provided (default /32) -D : IPv4 only - use default cidr (ClassA/8, ClassB/16, ClassC/24) Actions -h : help message -s cidr : split network into cidr subnets -w : supernet networks into smallest possible subnets -W : supernet networks into one single subnet -x : list all ipadresses in networks -C network : network contain networks -o network : network overlap networks -S network : substract network from subnet networks : one or more network addresses (1.2.3.4 10.0.0.0/8 10.0.0.0/255.0.0.0 2001:db8::/32 2001:db8:1:2:3:4:5:6/128 ) ``` -------------------------------- ### AddressFamily Property Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Gets the address family of the IP network (e.g., IPv4 or IPv6). ```APIDOC ## AddressFamily Property ### Description Gets address Family. ### Property Value - **AddressFamily** (AddressFamily) - The address family of the IP network. ``` -------------------------------- ### IPNetwork CLI Basic Usage Source: https://github.com/lduchosal/ipnetwork/blob/master/llms.txt The general command structure for the IPNetwork CLI tool, showing available options and arguments. ```bash ipnetwork [-inmcbflu] [-j] [-d cidr|-D] [-h|-s cidr|-S network|-w|-W|-x|-C network|-o network] networks ... ``` -------------------------------- ### Supernet Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Merges a list of IPNetwork2 objects into common supernets. For example, merging '192.168.0.0/24' and '192.168.1.0/24' results in '192.168.0.0/23'. ```APIDOC ## Supernet ### Description Merges a list of IPNetwork2 objects into common supernets. For example, merging '192.168.0.0/24' and '192.168.1.0/24' results in '192.168.0.0/23'. ### Method static IPNetwork2[] Supernet(IPNetwork2[] ipnetworks) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response - **Array of IPNetwork2**: The resulting supernets. ### Response Example None ``` -------------------------------- ### Compare Method Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Compares two IPNetwork2 instances to determine their relative order. Returns zero if the instances are equal, a negative value if the first instance is less than the second, and a positive value if the first instance is greater than the second. ```APIDOC ## Compare(IPNetwork2, IPNetwork2) ### Description Compares two IPNetwork2 instances. ### Method `public static int Compare(IPNetwork2 left, IPNetwork2 right)` #### Parameters - **left** (IPNetwork2) - The first IPNetwork2 instance to compare. - **right** (IPNetwork2) - The second IPNetwork2 instance to compare. ### Returns [int](https://learn.microsoft.com/dotnet/api/system.int32) - A value indicating the relative order of the two IPNetwork2 instances. Zero if the instances are equal. A negative value if `left` is less than `right`. A positive value if `left` is greater than `right`. ``` -------------------------------- ### Parse IPv6 Addresses with Different CIDR Guesses Source: https://github.com/lduchosal/ipnetwork/blob/master/README.md Demonstrates parsing an IPv6 address using different CIDR guessing strategies. Useful for understanding how the library interprets network masks. ```C# IPNetwork2 defaultParse = IPNetwork2.Parse("::1"); // default to ClassFull IPNetwork2 classFullParse = IPNetwork2.Parse("::1", CidrGuess.ClassFull); IPNetwork2 classLessParse = IPNetwork2.Parse("::1", CidrGuess.ClassLess); IPNetwork2 networkAwareParse = IPNetwork2.Parse("::1", CidrGuess.NetworkAware); Console.WriteLine("IPV6 Default Parse : {0}", defaultParse); Console.WriteLine("IPV6 ClassFull Parse : {0}", classFullParse); Console.WriteLine("IPV6 ClassLess Parse : {0}", classLessParse); Console.WriteLine("IPV6 NetworkAware Parse : {0}", networkAwareParse); ``` -------------------------------- ### Generate and Create IPv6 Unique Local Address (ULA) Subnets Source: https://github.com/lduchosal/ipnetwork/blob/master/README.md Demonstrates generating a random ULA prefix and creating specific subnets within it. Useful for setting up private IPv6 networks. ```C# // Generate a random ULA prefix var randomUla = UniqueLocalAddress.GenerateUlaPrefix(); Console.WriteLine($"Random ULA: {randomUla}"); // e.g., fd12:3456:789a::/48 // Create subnets with int subnet IDs (CLS-compliant) var subnet1 = UniqueLocalAddress.CreateUlaSubnet(randomUla, 1); var subnet2 = UniqueLocalAddress.CreateUlaSubnet(randomUla, 2); var maxSubnet = UniqueLocalAddress.CreateUlaSubnet(randomUla, UniqueLocalAddress.MaxSubnetId); Console.WriteLine($"Subnet 1: {subnet1}"); // e.g., fd12:3456: ``` -------------------------------- ### Chocolatey Package Structure Source: https://github.com/lduchosal/ipnetwork/blob/master/chocolatey/README.md Illustrates the directory layout for the Chocolatey package configuration. ```text chocolatey/ ├── ipnetwork.nuspec # Chocolatey package manifest ├── tools/ │ ├── chocolateyinstall.ps1 # Installation script │ └── chocolateyuninstall.ps1 # Uninstallation script └── README.md # This file ``` -------------------------------- ### Parsing IP Addresses with CIDR Guessing Strategies Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/doc/README.html Illustrates IPNetwork2.Parse with different CIDR guessing strategies (ClassFull and ClassLess) when the CIDR is not explicitly provided in the input string. ```csharp IPNetwork2 defaultParse= IPNetwork2.Parse("192.168.0.0"); // default to ClassFull IPNetwork2 classFullParse = IPNetwork2.Parse("192.168.0.0", CidrGuess.ClassFull); IPNetwork2 classLessParse = IPNetwork2.Parse("192.168.0.0", CidrGuess.ClassLess); Console.WriteLine("IPV4 Default Parse : {0}", defaultParse); Console.WriteLine("IPV4 ClassFull Parse : {0}", classFullParse); Console.WriteLine("IPV4 ClassLess Parse : {0}", classLessParse); ``` -------------------------------- ### TryToCidr Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Converts a netmask IPAddress to its CIDR notation. For example, 255.255.255.0 becomes 24, 255.255.0.0 becomes 16, and 255.0.0.0 becomes 8. ```APIDOC ## TryToCidr(IPAddress, out byte?) ### Description Converts a netmask IPAddress to its CIDR notation. For example, 255.255.255.0 becomes 24, 255.255.0.0 becomes 16, and 255.0.0.0 becomes 8. ### Method static bool TryToCidr(IPAddress netmask, out byte? cidr) ### Parameters #### Path Parameters - `netmask` (IPAddress) - An IPAdress representing the CIDR to convert. - `cidr` (byte)? - A byte representing the netmask in cidr format (/24). #### Returns - `bool` - true if netmask was converted successfully; otherwise, false. ``` -------------------------------- ### Parse and Get IPv4 Network Details Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/doc/README.html Parses an IPv4 network address and displays its network, netmask, broadcast, usable IP ranges, and CIDR. ```csharp IPNetwork2 ipnetwork = IPNetwork2.Parse("192.168.168.100/24"); Console.WriteLine("Network : {0}", ipnetwork.Network); Console.WriteLine("Netmask : {0}", ipnetwork.Netmask); Console.WriteLine("Broadcast : {0}", ipnetwork.Broadcast); Console.WriteLine("FirstUsable : {0}", ipnetwork.FirstUsable); Console.WriteLine("LastUsable : {0}", ipnetwork.LastUsable); Console.WriteLine("Usable : {0}", ipnetwork.Usable); Console.WriteLine("Cidr : {0}", ipnetwork.Cidr); ``` -------------------------------- ### Split Network into CIDR Subnets Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/doc/README.html Demonstrates splitting a given network into smaller subnets with a specified CIDR. This is useful for network segmentation. ```bash c:\\> ipnetwork -s 9 10.0.0.0/8 IPNetwork : 10.0.0.0/9 Network : 10.0.0.0 Netmask : 255.128.0.0 Cidr : 9 Broadcast : 10.127.255.255 FirstUsable : 10.0.0.1 LastUsable : 10.127.255.254 Usable : 8388606 -- IPNetwork : 10.128.0.0/9 Network : 10.128.0.0 Netmask : 255.128.0.0 Cidr : 9 Broadcast : 10.255.255.255 FirstUsable : 10.128.0.1 LastUsable : 10.255.255.254 Usable : 8388606 ``` -------------------------------- ### Parse and Get IPv6 Network Details Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/doc/README.html Parses an IPv6 network address and displays its network, netmask, broadcast, usable IP ranges, and CIDR. ```csharp IPNetwork2 ipnetwork = IPNetwork2.Parse("2001:0db8::/64"); Console.WriteLine("Network : {0}", ipnetwork.Network); Console.WriteLine("Netmask : {0}", ipnetwork.Netmask); Console.WriteLine("Broadcast : {0}", ipnetwork.Broadcast); Console.WriteLine("FirstUsable : {0}", ipnetwork.FirstUsable); Console.WriteLine("LastUsable : {0}", ipnetwork.LastUsable); Console.WriteLine("Usable : {0}", ipnetwork.Usable); Console.WriteLine("Cidr : {0}", ipnetwork.Cidr); ``` -------------------------------- ### CompareTo Method Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Compares the current IPNetwork2 instance with another IPNetwork2 instance. This method is part of the IComparable interface. ```APIDOC ## CompareTo(IPNetwork2) ### Description Compare two ipnetworks. ### Method `public int CompareTo(IPNetwork2 other)` #### Parameters - **other** (IPNetwork2) - The other network to compare to. ### Returns [int](https://learn.microsoft.com/dotnet/api/system.int32) - A signed number indicating the relative values of this instance and value.. ``` -------------------------------- ### TryToNetmask Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Converts a CIDR value to its corresponding netmask IPAddress. For example, 24 becomes 255.255.255.0, 16 becomes 255.255.0.0, and 8 becomes 255.0.0.0. ```APIDOC ## TryToNetmask(byte, AddressFamily, out IPAddress) ### Description Converts a CIDR value to its corresponding netmask IPAddress. For example, 24 becomes 255.255.255.0, 16 becomes 255.255.0.0, and 8 becomes 255.0.0.0. ### Method static bool TryToNetmask(byte cidr, AddressFamily family, out IPAddress netmask) ### Parameters #### Path Parameters - `cidr` (byte) - A byte representing the netmask in cidr format (/24). - `family` (AddressFamily) - Either IPv4 or IPv6. - `netmask` (IPAddress) - The resulting netmask. #### Returns - `bool` - true if cidr was converted successfully; otherwise, false. ``` -------------------------------- ### IPNetwork2() Constructor Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Initializes a new instance of the IPNetwork2 class. This constructor is primarily for DataContractSerialization. It is recommended to use the static IPNetwork.Parse() method for creating IPNetwork instances. ```APIDOC ## IPNetwork2() ### Description Initializes a new instance of the IPNetwork2 class. Created for DataContractSerialization. Better use static methods IPNetwork.Parse() to create IPNetworks. ### Constructor public IPNetwork2() ``` -------------------------------- ### IPNetwork2(IPAddress, byte) Constructor Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Initializes a new instance of the IPNetwork2 class with a specified IP address and CIDR prefix length. This constructor is used to create a new IPNetwork object. ```APIDOC ## IPNetwork2(IPAddress, byte) ### Description Initializes a new instance of the IPNetwork2 class. Creates a new IPNetwork. ### Constructor public IPNetwork2(IPAddress ipaddress, byte cidr) ### Parameters #### Path Parameters - **ipaddress** (IPAddress) - An ipaddress. - **cidr** (byte) - A byte representing the netmask in cidr format (/24). ### Exceptions - **ArgumentNullException**: ipaddress is null. ``` -------------------------------- ### Supernet Networks into One Single Subnet Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/doc/README.html Demonstrates supernetting multiple networks into a single, largest possible subnet that encompasses all of them. Use this to find the overall network range. ```bash C:\\>ipnetwork -W 192.168.0.0/24 192.168.129.0/24 IPNetwork : 192.168.0.0/16 Network : 192.168.0.0 Netmask : 255.255.0.0 Cidr : 16 Broadcast : 192.168.255.255 FirstUsable : 192.168.0.1 LastUsable : 192.168.255.254 Usable : 65534 ``` -------------------------------- ### Print(IPNetwork2) Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html A static method to print an IPNetwork2 object in a clear string representation. This method is marked as obsolete and suggests using the instance Print() method instead. ```APIDOC ## Print(IPNetwork2) ### Description A static method to print an IPNetwork2 object in a clear string representation. This method is marked as obsolete and suggests using the instance Print() method instead. ### Method [Obsolete("static Print is deprecated, please use instance Print.")] public static string Print(IPNetwork2 ipnetwork) ### Parameters #### Parameters - **ipnetwork** (IPNetwork2) - The ipnetwork. ### Returns - **string** - Dump an IPNetwork representation as string. #### Exceptions - **ArgumentNullException** - When arg is null. ``` -------------------------------- ### Print IPNetwork2 Static Method (Obsolete) Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html This static method is obsolete and is used to print an IPNetwork2 object to a string. It is recommended to use the instance Print() method instead. ```csharp [Obsolete("static Print is deprecated, please use instance Print.")] public static string Print(IPNetwork2 ipnetwork) ``` -------------------------------- ### Print() Source: https://github.com/lduchosal/ipnetwork/blob/master/doc/_site/api/System.Net.IPNetwork2.html Prints an IPNetwork2 object in a clear, string representation. This instance method returns a string that details the IP network's properties. ```APIDOC ## Print() ### Description Prints an IPNetwork2 object in a clear, string representation. This instance method returns a string that details the IP network's properties. ### Method public string Print() ### Returns - **string** - Dump an IPNetwork representation as string. ```