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 uint  ToUint (IPAddress ipaddress)
  Convert an ipadress to decimal 0.0.0.0 -> 0 0.0.1.0 -> 256 More...
 
static bool  TryToUint (IPAddress ipaddress, out uint?uintIpAddress)
  Convert an ipadress to decimal 0.0.0.0 -> 0 0.0.1.0 -> 256 More...
 
static uint  ToUint (byte cidr)
  Convert a cidr to uint netmask More...
 
static bool  TryToUint (byte cidr, out uint?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)
  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, out IPAddress netmask)
  Convert CIDR to netmask 24 -> 255.255.255.0 16 -> 255.255.0.0 8 -> 255.0.0.0 More...
 
static byte  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 (uint ipaddress)
  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, out byte?cidr)
  Try to parse cidr. Have to be >= 0 and <= 32 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...
 
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...
 
uint  Usable [get]
  Number of usable IP adress in Network More...
 
double  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...
 

Detailed Description

IP Network utility class. Use IPNetwork.Parse to create instances.

Member Function Documentation

 

static byte LukeSkywalker.IPNetwork.IPNetwork.BitsSet ( IPAddress  netmask )  
static

Count bits set to 1 in netmask

Parameters
netmask  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.Contains ( IPNetwork  network,
    IPAddress  ipaddress 
  )    
static

return true if ipaddress is contained in network

Parameters
network  
ipaddress  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.Contains ( IPNetwork  network,
    IPNetwork  network2 
  )    
static

return true is network2 is fully contained in network

Parameters
network  
network2  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.IsIANAReserved ( IPAddress  ipaddress )  
static

return true if ipaddress is contained in IANA_ABLK_RESERVED1, IANA_BBLK_RESERVED1, IANA_CBLK_RESERVED1

Parameters
ipaddress  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.IsIANAReserved ( IPNetwork  ipnetwork )  
static

return true if ipnetwork is contained in IANA_ABLK_RESERVED1, IANA_BBLK_RESERVED1, IANA_CBLK_RESERVED1

Parameters
ipnetwork  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.Overlap ( IPNetwork  network,
    IPNetwork  network2 
  )    
static

return true is network2 overlap network

Parameters
network  
network2  
Returns

 

static IPNetwork LukeSkywalker.IPNetwork.IPNetwork.Parse ( string  ipaddress,
    string  netmask 
  )    
static

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

Parameters
ipaddress  
netmask  
Returns

 

static IPNetwork LukeSkywalker.IPNetwork.IPNetwork.Parse ( string  ipaddress,
    byte  cidr 
  )    
static

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

Parameters
ipaddress  
cidr  
Returns

 

static IPNetwork LukeSkywalker.IPNetwork.IPNetwork.Parse ( IPAddress  ipaddress,
    IPAddress  netmask 
  )    
static

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

Parameters
ipaddress  
netmask  
Returns

 

static IPNetwork LukeSkywalker.IPNetwork.IPNetwork.Parse ( string  network )  
static

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

Parameters
network  
Returns

 

static string LukeSkywalker.IPNetwork.IPNetwork.Print ( IPNetwork  ipnetwork )  
static

Print an ipnetwork in a clear representation string

Parameters
ipnetwork  
Returns

 

static IPNetworkCollection LukeSkywalker.IPNetwork.IPNetwork.Subnet ( IPNetwork  network,
    byte  cidr 
  )    
static

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

Parameters
ipnetwork  
cidr  
Returns

 

static IPNetwork LukeSkywalker.IPNetwork.IPNetwork.Supernet ( IPNetwork  network1,
    IPNetwork  network2 
  )    
static

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

Parameters
network1  
network2  
Returns

 

static IPNetwork [] LukeSkywalker.IPNetwork.IPNetwork.Supernet ( IPNetwork[]  ipnetworks )  
static

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

Parameters
ipnetworks  
supernet  
Returns

 

static byte LukeSkywalker.IPNetwork.IPNetwork.ToCidr ( IPAddress  netmask )  
static

Convert netmask to CIDR 255.255.255.0 -> 24 255.255.0.0 -> 16 255.0.0.0 -> 8

Parameters
netmask  
Returns

 

static IPAddress LukeSkywalker.IPNetwork.IPNetwork.ToIPAddress ( uint  ipaddress )  
static

Transform a uint ipaddress into IPAddress object

Parameters
ipaddress  
Returns

 

static IPAddress LukeSkywalker.IPNetwork.IPNetwork.ToNetmask ( byte  cidr )  
static

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/

Parameters
cidr  
Returns

 

static uint LukeSkywalker.IPNetwork.IPNetwork.ToUint ( IPAddress  ipaddress )  
static

Convert an ipadress to decimal 0.0.0.0 -> 0 0.0.1.0 -> 256

Parameters
ipaddress  
Returns

 

static uint LukeSkywalker.IPNetwork.IPNetwork.ToUint ( byte  cidr )  
static

Convert a cidr to uint netmask

Parameters
cidr  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TryGuessCidr ( string  ip,
    out byte  cidr 
  )    
static

 

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

Parameters
ip  
cidr  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TryParse ( string  ipaddress,
    string  netmask,
    out IPNetwork  ipnetwork 
  )    
static

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

Parameters
ipaddress  
netmask  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TryParse ( string  ipaddress,
    byte  cidr,
    out IPNetwork  ipnetwork 
  )    
static

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

Parameters
ipaddress  
cidr  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TryParse ( string  network,
    out IPNetwork  ipnetwork 
  )    
static

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

Parameters
network  
ipnetwork  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TryParse ( IPAddress  ipaddress,
    IPAddress  netmask,
    out IPNetwork  ipnetwork 
  )    
static

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

Parameters
ipaddress  
netmask  
ipnetwork  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TryParseCidr ( string  sidr,
    out byte?  cidr 
  )    
static

Try to parse cidr. Have to be >= 0 and <= 32

Parameters
sidr  
cidr  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TrySubnet ( IPNetwork  network,
    byte  cidr,
    out IPNetworkCollection  ipnetworkCollection 
  )    
static

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

Parameters
ipnetwork  
cidr  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TrySupernet ( IPNetwork  network1,
    IPNetwork  network2,
    out IPNetwork  supernet 
  )    
static

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

Parameters
network1  
network2  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TrySupernet ( IPNetwork[]  ipnetworks,
    out IPNetwork[]  supernet 
  )    
static

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

Parameters
ipnetworks  
supernet  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TryToCidr ( IPAddress  netmask,
    out byte?  cidr 
  )    
static

Convert netmask to CIDR 255.255.255.0 -> 24 255.255.0.0 -> 16 255.0.0.0 -> 8

Parameters
netmask  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TryToNetmask ( byte  cidr,
    out IPAddress  netmask 
  )    
static

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/

Parameters
cidr  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TryToUint ( IPAddress  ipaddress,
    out uint?  uintIpAddress 
  )    
static

Convert an ipadress to decimal 0.0.0.0 -> 0 0.0.1.0 -> 256

Parameters
ipaddress  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.TryToUint ( byte  cidr,
    out uint?  uintNetmask 
  )    
static

Convert a cidr to uint netmask

Parameters
cidr  
Returns

 

static bool LukeSkywalker.IPNetwork.IPNetwork.ValidNetmask ( IPAddress  netmask )  
static

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-

Parameters
netmask  
Returns

Property Documentation

 

IPAddress LukeSkywalker.IPNetwork.IPNetwork.Broadcast
get

Broadcast address

 

byte LukeSkywalker.IPNetwork.IPNetwork.Cidr
get

The CIDR netmask notation

 

IPAddress LukeSkywalker.IPNetwork.IPNetwork.FirstUsable
get

First usable IP adress in Network

 

IPNetwork LukeSkywalker.IPNetwork.IPNetwork.IANA_ABLK_RESERVED1
staticget

10.0.0.0/8

Returns

 

IPNetwork LukeSkywalker.IPNetwork.IPNetwork.IANA_BBLK_RESERVED1
staticget

172.12.0.0/12

Returns

 

IPNetwork LukeSkywalker.IPNetwork.IPNetwork.IANA_CBLK_RESERVED1
staticget

192.168.0.0/16

Returns

 

IPAddress LukeSkywalker.IPNetwork.IPNetwork.LastUsable
get

Last usable IP adress in Network

 

IPAddress LukeSkywalker.IPNetwork.IPNetwork.Netmask
get

Netmask

 

IPAddress LukeSkywalker.IPNetwork.IPNetwork.Network
get

Network address

 

double LukeSkywalker.IPNetwork.IPNetwork.Total
get

Number of IP adress in Network

 

uint LukeSkywalker.IPNetwork.IPNetwork.Usable
get

Number of usable IP adress in Network 

Last edited Apr 22, 2014 at 7:57 AM by LukeSkywalker, version 1

Comments

No comments yet.