IPNetwork
2.0.1
IPNetwork utility computes your ip, ipv4, ipv6, netmask, cidr, subnet, supernet and network
|
IP Network utility class. Use IPNetwork.Parse to create instances. More...
Public Member Functions | |
override string | ToString () |
override int | GetHashCode () |
Int32 | CompareTo (IPNetwork other) |
Int32 | CompareTo (Object obj) |
Boolean | Equals (IPNetwork other) |
override Boolean | Equals (Object obj) |
Static Public Member Functions | |
static IPNetwork | Parse (string ipaddress, string netmask) |
192.168.168.100 - 255.255.255.0 More... | |
static IPNetwork | Parse (string ipaddress, byte cidr) |
192.168.168.100/24 More... | |
static IPNetwork | Parse (IPAddress ipaddress, IPAddress netmask) |
192.168.168.100 255.255.255.0 More... | |
static IPNetwork | Parse (string network) |
192.168.0.1/24 192.168.0.1 255.255.255.0 More... | |
static bool | TryParse (string ipaddress, string netmask, out IPNetwork ipnetwork) |
192.168.168.100 - 255.255.255.0 More... | |
static bool | TryParse (string ipaddress, byte cidr, out IPNetwork ipnetwork) |
192.168.168.100/24 More... | |
static bool | TryParse (string network, out IPNetwork ipnetwork) |
192.168.0.1/24 192.168.0.1 255.255.255.0 More... | |
static bool | TryParse (IPAddress ipaddress, IPAddress netmask, out IPNetwork ipnetwork) |
192.168.0.1/24 192.168.0.1 255.255.255.0 More... | |
static BigInteger | ToBigInteger (IPAddress ipaddress) |
Convert an ipadress to decimal 0.0.0.0 -> 0 0.0.1.0 -> 256 More... | |
static bool | TryToBigInteger (IPAddress ipaddress, out BigInteger?uintIpAddress) |
Convert an ipadress to decimal 0.0.0.0 -> 0 0.0.1.0 -> 256 More... | |
static BigInteger | ToUint (byte cidr, AddressFamily family) |
Convert a cidr to BigInteger netmask More... | |
static bool | TryToUint (byte cidr, AddressFamily family, out BigInteger?uintNetmask) |
Convert a cidr to uint netmask More... | |
static byte | ToCidr (IPAddress netmask) |
Convert netmask to CIDR 255.255.255.0 -> 24 255.255.0.0 -> 16 255.0.0.0 -> 8 More... | |
static bool | TryToCidr (IPAddress netmask, out byte?cidr) |
Convert netmask to CIDR 255.255.255.0 -> 24 255.255.0.0 -> 16 255.0.0.0 -> 8 More... | |
static IPAddress | ToNetmask (byte cidr, AddressFamily family) |
Convert CIDR to netmask 24 -> 255.255.255.0 16 -> 255.255.0.0 8 -> 255.0.0.0 More... | |
static bool | TryToNetmask (byte cidr, AddressFamily family, out IPAddress netmask) |
Convert CIDR to netmask 24 -> 255.255.255.0 16 -> 255.255.0.0 8 -> 255.0.0.0 More... | |
static uint | BitsSet (IPAddress netmask) |
Count bits set to 1 in netmask More... | |
static bool | ValidNetmask (IPAddress netmask) |
return true if netmask is a valid netmask 255.255.255.0, 255.0.0.0, 255.255.240.0, ... More... | |
static IPAddress | ToIPAddress (BigInteger ipaddress, AddressFamily family) |
Transform a uint ipaddress into IPAddress object More... | |
static bool | Contains (IPNetwork network, IPAddress ipaddress) |
return true if ipaddress is contained in network More... | |
static bool | Contains (IPNetwork network, IPNetwork network2) |
return true is network2 is fully contained in network More... | |
static bool | Overlap (IPNetwork network, IPNetwork network2) |
return true is network2 overlap network More... | |
static bool | IsIANAReserved (IPAddress ipaddress) |
return true if ipaddress is contained in IANA_ABLK_RESERVED1, IANA_BBLK_RESERVED1, IANA_CBLK_RESERVED1 More... | |
static bool | IsIANAReserved (IPNetwork ipnetwork) |
return true if ipnetwork is contained in IANA_ABLK_RESERVED1, IANA_BBLK_RESERVED1, IANA_CBLK_RESERVED1 More... | |
static IPNetworkCollection | Subnet (IPNetwork network, byte cidr) |
Subnet a network into multiple nets of cidr mask Subnet 192.168.0.0/24 into cidr 25 gives 192.168.0.0/25, 192.168.0.128/25 Subnet 10.0.0.0/8 into cidr 9 gives 10.0.0.0/9, 10.128.0.0/9 More... | |
static bool | TrySubnet (IPNetwork network, byte cidr, out IPNetworkCollection ipnetworkCollection) |
Subnet a network into multiple nets of cidr mask Subnet 192.168.0.0/24 into cidr 25 gives 192.168.0.0/25, 192.168.0.128/25 Subnet 10.0.0.0/8 into cidr 9 gives 10.0.0.0/9, 10.128.0.0/9 More... | |
static IPNetwork | Supernet (IPNetwork network1, IPNetwork network2) |
Supernet two consecutive cidr equal subnet into a single one 192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23 10.1.0.0/16 + 10.0.0.0/16 = 10.0.0.0/15 192.168.0.0/24 + 192.168.0.0/25 = 192.168.0.0/24 More... | |
static bool | TrySupernet (IPNetwork network1, IPNetwork network2, out IPNetwork supernet) |
Try to supernet two consecutive cidr equal subnet into a single one 192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23 10.1.0.0/16 + 10.0.0.0/16 = 10.0.0.0/15 192.168.0.0/24 + 192.168.0.0/25 = 192.168.0.0/24 More... | |
static IPNetwork[] | Supernet (IPNetwork[] ipnetworks) |
Supernet a list of subnet 192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23 192.168.0.0/24 + 192.168.1.0/24 + 192.168.2.0/24 + 192.168.3.0/24 = 192.168.0.0/22 More... | |
static bool | TrySupernet (IPNetwork[] ipnetworks, out IPNetwork[] supernet) |
Supernet a list of subnet 192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23 192.168.0.0/24 + 192.168.1.0/24 + 192.168.2.0/24 + 192.168.3.0/24 = 192.168.0.0/22 More... | |
static bool | InternalSupernet (bool trySupernet, IPNetwork[] ipnetworks, out IPNetwork[] supernet) |
static IPNetwork | WideSubnet (string start, string end) |
static bool | TryWideSubnet (IPNetwork[] ipnetworks, out IPNetwork ipnetwork) |
static IPNetwork | WideSubnet (IPNetwork[] ipnetworks) |
static string | Print (IPNetwork ipnetwork) |
Print an ipnetwork in a clear representation string More... | |
static bool | TryGuessCidr (string ip, out byte cidr) |
static bool | TryParseCidr (string sidr, AddressFamily family, out byte?cidr) |
Try to parse cidr. Have to be >= 0 and <= 32 or 128 More... | |
static IPAddressCollection | ListIPAddress (IPNetwork ipnetwork) |
static Int32 | Compare (IPNetwork left, IPNetwork right) |
static Boolean | Equals (IPNetwork left, IPNetwork right) |
static Boolean | operator== (IPNetwork left, IPNetwork right) |
static Boolean | operator!= (IPNetwork left, IPNetwork right) |
static Boolean | operator< (IPNetwork left, IPNetwork right) |
static Boolean | operator> (IPNetwork left, IPNetwork right) |
Properties | |
IPAddress | Network [get] |
Network address More... | |
AddressFamily | AddressFamily [get] |
Address Family More... | |
IPAddress | Netmask [get] |
Netmask More... | |
IPAddress | Broadcast [get] |
Broadcast address More... | |
IPAddress | FirstUsable [get] |
First usable IP adress in Network More... | |
IPAddress | LastUsable [get] |
Last usable IP adress in Network More... | |
BigInteger | Usable [get] |
Number of usable IP adress in Network More... | |
BigInteger | Total [get] |
Number of IP adress in Network More... | |
byte | Cidr [get] |
The CIDR netmask notation More... | |
static IPNetwork | IANA_ABLK_RESERVED1 [get] |
10.0.0.0/8 More... | |
static IPNetwork | IANA_BBLK_RESERVED1 [get] |
172.12.0.0/12 More... | |
static IPNetwork | IANA_CBLK_RESERVED1 [get] |
192.168.0.0/16 More... | |
IP Network utility class. Use IPNetwork.Parse to create instances.
|
inlinestatic |
Count bits set to 1 in netmask
netmask |
Need a better way to do it
#region TrySubstractNetwork
public static bool TrySubstractNetwork(IPNetwork[] ipnetworks, IPNetwork substract, out IEnumerable<IPNetwork> result) {
if (ipnetworks == null) { result = null; return false; } if (ipnetworks.Length <= 0) { result = null; return false; } if (substract == null) { result = null; return false; } var results = new List<IPNetwork>(); foreach (var ipn in ipnetworks) { if (!Overlap(ipn, substract)) { results.Add(ipn); continue; } var collection = IPNetwork.Subnet(ipn, substract.Cidr); var rtemp = new List<IPNetwork>(); foreach(var subnet in collection) { if (subnet != substract) { rtemp.Add(subnet); } } var supernets = Supernet(rtemp.ToArray()); results.AddRange(supernets); } result = results; return true;
} #endregion
|
inlinestatic |
return true if ipaddress is contained in network
network | |
ipaddress |
return true is network2 is fully contained in network
network | |
network2 |
|
inlinestatic |
return true if ipaddress is contained in IANA_ABLK_RESERVED1, IANA_BBLK_RESERVED1, IANA_CBLK_RESERVED1
ipaddress |
|
inlinestatic |
return true if ipnetwork is contained in IANA_ABLK_RESERVED1, IANA_BBLK_RESERVED1, IANA_CBLK_RESERVED1
ipnetwork |
return true is network2 overlap network
network | |
network2 |
|
inlinestatic |
192.168.168.100 - 255.255.255.0
Network : 192.168.168.0 Netmask : 255.255.255.0 Cidr : 24 Start : 192.168.168.1 End : 192.168.168.254 Broadcast : 192.168.168.255
ipaddress | |
netmask |
|
inlinestatic |
192.168.168.100/24
Network : 192.168.168.0 Netmask : 255.255.255.0 Cidr : 24 Start : 192.168.168.1 End : 192.168.168.254 Broadcast : 192.168.168.255
ipaddress | |
cidr |
|
inlinestatic |
192.168.168.100 255.255.255.0
Network : 192.168.168.0 Netmask : 255.255.255.0 Cidr : 24 Start : 192.168.168.1 End : 192.168.168.254 Broadcast : 192.168.168.255
ipaddress | |
netmask |
|
inlinestatic |
192.168.0.1/24 192.168.0.1 255.255.255.0
Network : 192.168.0.0 Netmask : 255.255.255.0 Cidr : 24 Start : 192.168.0.1 End : 192.168.0.254 Broadcast : 192.168.0.255
network |
|
inlinestatic |
Print an ipnetwork in a clear representation string
ipnetwork |
|
inlinestatic |
Subnet a network into multiple nets of cidr mask Subnet 192.168.0.0/24 into cidr 25 gives 192.168.0.0/25, 192.168.0.128/25 Subnet 10.0.0.0/8 into cidr 9 gives 10.0.0.0/9, 10.128.0.0/9
ipnetwork | |
cidr |
|
inlinestatic |
Supernet two consecutive cidr equal subnet into a single one 192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23 10.1.0.0/16 + 10.0.0.0/16 = 10.0.0.0/15 192.168.0.0/24 + 192.168.0.0/25 = 192.168.0.0/24
network1 | |
network2 |
Supernet a list of subnet 192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23 192.168.0.0/24 + 192.168.1.0/24 + 192.168.2.0/24 + 192.168.3.0/24 = 192.168.0.0/22
ipnetworks | |
supernet |
|
inlinestatic |
Convert an ipadress to decimal 0.0.0.0 -> 0 0.0.1.0 -> 256
ipaddress |
|
inlinestatic |
Convert netmask to CIDR 255.255.255.0 -> 24 255.255.0.0 -> 16 255.0.0.0 -> 8
netmask |
|
inlinestatic |
Transform a uint ipaddress into IPAddress object
ipaddress |
|
inlinestatic |
Convert CIDR to netmask 24 -> 255.255.255.0 16 -> 255.255.0.0 8 -> 255.0.0.0
http://snipplr.com/view/15557/cidr-class-for-ipv4/
cidr |
|
inlinestatic |
Convert a cidr to BigInteger netmask
cidr |
|
inlinestatic |
Class Leading bits Default netmask A (CIDR /8) 00 255.0.0.0 A (CIDR /8) 01 255.0.0.0 B (CIDR /16) 10 255.255.0.0 C (CIDR /24) 11 255.255.255.0
ip | |
cidr |
|
inlinestatic |
192.168.168.100 - 255.255.255.0
Network : 192.168.168.0 Netmask : 255.255.255.0 Cidr : 24 Start : 192.168.168.1 End : 192.168.168.254 Broadcast : 192.168.168.255
ipaddress | |
netmask |
|
inlinestatic |
192.168.168.100/24
Network : 192.168.168.0 Netmask : 255.255.255.0 Cidr : 24 Start : 192.168.168.1 End : 192.168.168.254 Broadcast : 192.168.168.255
ipaddress | |
cidr |
|
inlinestatic |
192.168.0.1/24 192.168.0.1 255.255.255.0
Network : 192.168.0.0 Netmask : 255.255.255.0 Cidr : 24 Start : 192.168.0.1 End : 192.168.0.254 Broadcast : 192.168.0.255
network | |
ipnetwork |
|
inlinestatic |
192.168.0.1/24 192.168.0.1 255.255.255.0
Network : 192.168.0.0 Netmask : 255.255.255.0 Cidr : 24 Start : 192.168.0.1 End : 192.168.0.254 Broadcast : 192.168.0.255
ipaddress | |
netmask | |
ipnetwork |
|
inlinestatic |
Try to parse cidr. Have to be >= 0 and <= 32 or 128
sidr | |
cidr |
|
inlinestatic |
Subnet a network into multiple nets of cidr mask Subnet 192.168.0.0/24 into cidr 25 gives 192.168.0.0/25, 192.168.0.128/25 Subnet 10.0.0.0/8 into cidr 9 gives 10.0.0.0/9, 10.128.0.0/9
ipnetwork | |
cidr |
|
inlinestatic |
Try to supernet two consecutive cidr equal subnet into a single one 192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23 10.1.0.0/16 + 10.0.0.0/16 = 10.0.0.0/15 192.168.0.0/24 + 192.168.0.0/25 = 192.168.0.0/24
network1 | |
network2 |
|
inlinestatic |
Supernet a list of subnet 192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23 192.168.0.0/24 + 192.168.1.0/24 + 192.168.2.0/24 + 192.168.3.0/24 = 192.168.0.0/22
ipnetworks | |
supernet |
|
inlinestatic |
Convert an ipadress to decimal 0.0.0.0 -> 0 0.0.1.0 -> 256
ipaddress |
|
inlinestatic |
Convert netmask to CIDR 255.255.255.0 -> 24 255.255.0.0 -> 16 255.0.0.0 -> 8
netmask |
|
inlinestatic |
Convert CIDR to netmask 24 -> 255.255.255.0 16 -> 255.255.0.0 8 -> 255.0.0.0
http://snipplr.com/view/15557/cidr-class-for-ipv4/
cidr |
|
inlinestatic |
Convert a cidr to uint netmask
cidr |
|
inlinestatic |
return true if netmask is a valid netmask 255.255.255.0, 255.0.0.0, 255.255.240.0, ...
http://www.actionsnip.com/snippets/tomo_atlacatl/calculate-if-a-netmask-is-valid--as2-
netmask |
|
get |
Address Family
|
get |
Broadcast address
|
get |
The CIDR netmask notation
|
get |
First usable IP adress in Network
|
staticget |
10.0.0.0/8
|
staticget |
172.12.0.0/12
|
staticget |
192.168.0.0/16
|
get |
Last usable IP adress in Network
|
get |
Netmask
|
get |
Network address
|
get |
Number of IP adress in Network
|
get |
Number of usable IP adress in Network