IP Address Utilities¶
Arcus.Utilities.IPAddressUtilities is a static utility class containing miscellaneous methods and definitions for the
Included within are some handy-dandy constant values and static readonly properties:
The number of bits in an IPv4 address (
The number of bytes in an IPv4 address (
The number of octets in an IPv4 address (
The number of bits in an IPv6 address (
The number of bytes in an IPv6 address (
The number of hextets in an IPv6 address (
The maximum IPv4 Address value (
The minimum IPv4 Address value (
The maximum IPv6 value (
The minimum IPv6 value (
The standard valid
Minimum and Maximum Address¶
Given an instance of
MaxIPAddress methods will return the minimum value of an address with the
AddressFamily or the maximum value respectively.
these methods are only valid for
public static IPAddress MinIPAddress(this AddressFamily addressFamily)
public static IPAddress MaxIPAddress(this AddressFamily addressFamily)
Address Family Detection¶
Given an instance of
IPAddress ipAddress the
IsIPv6 methods will return
true if the given address has the address family
public static bool IsIPv4(this IPAddress ipAddress)
public static bool IsIPv6(this IPAddress ipAddress)
Address Format Detection¶
Arcus provides a few ways to detect the format of an
IPAddress that isn’t already built into the pre-existing C# packages.
IsIPv4MappedIPv6 will return
true if, and only if,``IPAddress ipAddress`` is an IPv4 addressed mapped to IPv6.
This check is made in accordance of in accordance to RFC4291 - IP Version 6 Addressing Architecture - 22.214.171.124. “IPv4-Mapped IPv6 Address.”
public static bool IsIPv4MappedIPv6(this IPAddress ipAddress)
IsValidNetMask checks if the given
IPAddress netmask is a valid IPv4 netmask, if, and only if, it is then the method returns
public static bool IsValidNetMask(this IPAddress netmask)
Arcus provides a few more out of the box parsing mechanisms to convert different types of input into an
Most of these new parsing routines have a “safe” method that will be prefixed by “Try” that will return
true on a successful parsing and will out the
TryParseFromHexString will attempt to parse a hexadecimal
string input as an IP Address of the given
Valid input must be comprised of only hexadecimal characters with an optional “0x” prefix. Input is case insensitive, and assumed to be in big-endian byte order. Zero valued most significant bytes will be ignored.
public static IPAddress ParseFromHexString(string input, AddressFamily addressFamily)
public static bool TryParseFromHexString(string input, AddressFamily addressFamily, out IPAddress address)
By Microsoft’s implementation of the
IPAddress.Parse(string) any string representation of an IP Address having a zero-valued most significant number in an octet position is interpreted as octal (base 8) rather than decimal (base 10). This isn’t always a desired way to go about parsing values.
These methods convert an
string input IPv4 address representation to
IPAddress instance ignoring leading zeros (octal notation) of dotted quad format.
public static IPAddress ParseIgnoreOctalInIPv4(string input)
public static bool TryParseIgnoreOctalInIPv4(string input, out IPAddress address)
byte parsing methods will attempt to convert a big-endian ordered byte array to an
IPAddress automatically providing the appropriate number of zero-valued most significant bytes as needed to meet the desired address family.
This implementation differs from the constructor implementation on
IPAddress that takes
byte as input. Said constructor takes an explicit sized byte array and will outright fail if the input isn’t explicitly 4 or 16 bytes long.
public static IPAddress Parse(byte input, AddressFamily addressFamily)
public static bool TryParse(byte input, AddressFamily addressFamily, out IPAddress address)