Skip to main content

IPAddressExtensions

Useful IPAddressExtensions from: http://blogs.msdn.com/knom/archive/2008/12/31/ip-address-calculations-with-c-subnetmasks-networks.aspx

Assembly: ServiceStack.Common.dll
View Source
Declaration
public static class IPAddressExtensions

Methods

GetBroadcastAddress(IPAddress, IPAddress)

View Source
Declaration
public static IPAddress GetBroadcastAddress(this IPAddress address, IPAddress subnetMask)
Returns

System.Net.IPAddress

Parameters
TypeName
System.Net.IPAddressaddress
System.Net.IPAddresssubnetMask

GetNetworkAddress(IPAddress, IPAddress)

View Source
Declaration
public static IPAddress GetNetworkAddress(this IPAddress address, IPAddress subnetMask)
Returns

System.Net.IPAddress

Parameters
TypeName
System.Net.IPAddressaddress
System.Net.IPAddresssubnetMask

GetNetworkAddressBytes(Byte[], Byte[])

View Source
Declaration
public static byte[] GetNetworkAddressBytes(byte[] ipAdressBytes, byte[] subnetMaskBytes)
Returns

System.Byte[]

Parameters
TypeName
System.Byte[]ipAdressBytes
System.Byte[]subnetMaskBytes

IsInSameIpv6Subnet(IPAddress, IPAddress)

View Source
Declaration
public static bool IsInSameIpv6Subnet(this IPAddress address2, IPAddress address)
Returns

System.Boolean

Parameters
TypeName
System.Net.IPAddressaddress2
System.Net.IPAddressaddress

IsInSameIpv6Subnet(Byte[], Byte[])

View Source
Declaration
public static bool IsInSameIpv6Subnet(this byte[] address1Bytes, byte[] address2Bytes)
Returns

System.Boolean

Parameters
TypeName
System.Byte[]address1Bytes
System.Byte[]address2Bytes

IsInSameIpv4Subnet(IPAddress, IPAddress, IPAddress)

View Source
Declaration
public static bool IsInSameIpv4Subnet(this IPAddress address2, IPAddress address, IPAddress subnetMask)
Returns

System.Boolean

Parameters
TypeName
System.Net.IPAddressaddress2
System.Net.IPAddressaddress
System.Net.IPAddresssubnetMask

IsInSameIpv4Subnet(Byte[], Byte[], Byte[])

View Source
Declaration
public static bool IsInSameIpv4Subnet(this byte[] address1Bytes, byte[] address2Bytes, byte[] subnetMaskBytes)
Returns

System.Boolean

Parameters
TypeName
System.Byte[]address1Bytes
System.Byte[]address2Bytes
System.Byte[]subnetMaskBytes

GetAllNetworkInterfaceIpv4Addresses()

Gets the ipv4 addresses from all Network Interfaces that have Subnet masks.

View Source
Declaration
public static Dictionary<IPAddress, IPAddress> GetAllNetworkInterfaceIpv4Addresses()
Returns

System.Collections.Generic.Dictionary<System.Net.IPAddress,System.Net.IPAddress>

GetAllNetworkInterfaceIpv6Addresses()

Gets the ipv6 addresses from all Network Interfaces.

View Source
Declaration
public static List<IPAddress> GetAllNetworkInterfaceIpv6Addresses()
Returns

System.Collections.Generic.List<System.Net.IPAddress>