Table of Contents

Class IpHelper

Namespace
Dynamicweb.Core.Helpers
Assembly
Dynamicweb.Core.dll
public static class IpHelper
Inheritance
IpHelper
Inherited Members

Methods

IsIpAddressInCidrRange(IPAddress, string?)

Determines whether an IP address falls within a specified CIDR range.

public static bool IsIpAddressInCidrRange(IPAddress ipAddress, string? cidrNotation)

Parameters

ipAddress IPAddress

The IP address to check.

cidrNotation string

The CIDR notation string (e.g., "192.168.1.0/24" or "2001:db8::/32").

Returns

bool

true if the IP address is within the CIDR range; otherwise, false.

Remarks

This method supports both IPv4 and IPv6 CIDR notation. The IP address and network address are automatically normalized to handle IPv4-mapped IPv6 addresses. If the address families don't match, the method attempts to normalize the network address.

Exceptions

ArgumentNullException

Thrown when ipAddress is null.

IsIpAddressInRange(IPAddress, string?)

Determines whether an IP address falls within a specified IP address range.

public static bool IsIpAddressInRange(IPAddress ipAddress, string? ipAddressesRange)

Parameters

ipAddress IPAddress

The IP address to check.

ipAddressesRange string

The IP address range in the format "startIP-endIP" (e.g., "192.168.1.1-192.168.1.100" or "2001:db8::1-2001:db8::ffff").

Returns

bool

true if the IP address is within the specified range; otherwise, false.

Remarks

This method supports both IPv4 and IPv6 address ranges. The range format is "startIP-endIP" where both addresses must be valid IP addresses of the same family. Nested ranges and wildcard characters are not allowed within the range specification.

Exceptions

ArgumentNullException

Thrown when ipAddress is null.

IsIpAddressInWildcardRange(IPAddress, string?)

Determines whether an IP address matches a wildcard pattern.

public static bool IsIpAddressInWildcardRange(IPAddress ipAddress, string? wildcardPattern)

Parameters

ipAddress IPAddress

The IP address to check.

wildcardPattern string

The wildcard pattern to match against (e.g., "192.168.1."). Must end with "." and be a valid IPv4 pattern.

Returns

bool

true if the IP address matches the wildcard pattern; otherwise, false.

Remarks

This method only supports IPv4 wildcard patterns. The pattern must end with "." and the prefix must be a valid IPv4 address prefix. For example, "192.168.1." will match any IP address starting with "192.168.1.".

Exceptions

ArgumentNullException

Thrown when ipAddress is null.

MatchesPattern(IPAddress, string?)

Determines whether an IP address matches a specified pattern.

public static bool MatchesPattern(IPAddress ipAddress, string? ipAddressPattern)

Parameters

ipAddress IPAddress

The IP address to check.

ipAddressPattern string

The pattern to match against. Supports exact IP addresses, CIDR notation (e.g., "192.168.1.0/24"), IP ranges (e.g., "192.168.1.1-192.168.1.100"), and wildcard patterns (e.g., "192.168.1.*" for IPv4 only).

Returns

bool

true if the IP address matches the pattern; otherwise, false.

Remarks

This method supports multiple pattern formats:

  • Exact IP address: "192.168.1.1" or "2001:db8::1"
  • CIDR notation: "192.168.1.0/24" or "2001:db8::/32"
  • IP range: "192.168.1.1-192.168.1.100" or "2001:db8::1-2001:db8::ffff"
  • Wildcard (IPv4 only): "192.168.1.*"

Both IPv4 and IPv6 addresses are supported, with automatic normalization of IPv4-mapped IPv6 addresses.

Exceptions

ArgumentNullException

Thrown when ipAddress is null.

To top