IPUtils
Parse, match, and analyze IP addresses and CIDR ranges
|
Play with IP addresses and IP ranges. More...
Static Public Member Functions | |
static | isIPAddress ( $ip) |
Determine if a string is as valid IP address or network (CIDR prefix). | |
static | isIPv6 ( $ip) |
Given a string, determine if it as valid IP in IPv6 only. | |
static | isIPv4 ( $ip) |
Given a string, determine if it as valid IP in IPv4 only. | |
static | isValid ( $ip) |
Validate an IP address. | |
static | isValidIPv4 ( $ip) |
Validate an IPv4 address. | |
static | isValidIPv6 ( $ip) |
Validate an IPv6 address. | |
static | isValidRange ( $ipRange) |
Validate an IP range (valid in either IPv4 OR IPv6; given with valid CIDR prefix or in explicit notation). | |
static | sanitizeIP ( $ip) |
Convert an IP into a verbose, uppercase, normalized form. | |
static | prettifyIP ( $ip) |
Prettify an IP for display to end users. | |
static | splitHostAndPort ( $both) |
Given a host/port string, like one might find in the host part of a URL per RFC 2732, split the hostname part and the port part and return an array with an element for each. | |
static | combineHostAndPort ( $host, $port, $defaultPort=false) |
Given a host name and a port, combine them into host/port string like you might find in a URL. | |
static | formatHex ( $hex) |
Convert an IPv4 or IPv6 hexadecimal representation back to readable format. | |
static | hexToOctet ( $ip_hex) |
Converts a hexadecimal number to an IPv6 address in octet notation. | |
static | hexToQuad ( $ip_hex) |
Converts a hexadecimal number to an IPv4 address in quad-dotted notation. | |
static | isPublic ( $ip) |
Determine if an IP address really is an IP address, and if it is public, i.e. | |
static | toHex ( $ip) |
Return a zero-padded upper case hexadecimal representation of an IP address. | |
static | parseCIDR ( $range) |
Convert a network specification in CIDR notation to an integer network and a number of bits. | |
static | parseRange ( $range) |
Given a string range in a number of formats, return the start and end of the range in hexadecimal. | |
static | isInRange ( $addr, $range) |
Determine if a given IPv4/IPv6 address is in a given CIDR network. | |
static | isInRanges ( $ip, $ranges) |
Determines if an IP address is a list of CIDR a.b.c.d/n ranges. | |
static | canonicalize ( $addr) |
Convert some unusual representations of IPv4 addresses to their canonical dotted quad representation. | |
static | sanitizeRange ( $range) |
Gets rid of unneeded numbers in quad-dotted/octet IP strings For example, 127.111.113.151/24 -> 127.111.113.0/24. | |
static | getSubnet ( $ip) |
Returns the subnet of a given IP. | |
static | getIPsInRange ( $range) |
Return all the addresses in a given range. | |
Play with IP addresses and IP ranges.
|
static |
Convert some unusual representations of IPv4 addresses to their canonical dotted quad representation.
This currently only checks a few IPV4-to-IPv6 related cases. More unusual representations may be added later.
string | $addr | Something that might be an IP address |
|
static |
Given a host name and a port, combine them into host/port string like you might find in a URL.
If the host contains a colon, wrap it in square brackets like in RFC 2732. If the port matches the default port, omit the port specification
string | $host | |
int | $port | |
bool | int | $defaultPort |
|
static |
Convert an IPv4 or IPv6 hexadecimal representation back to readable format.
string | $hex | Number, with "v6-" prefix if it is IPv6 |
|
static |
Return all the addresses in a given range.
This currently does not support IPv6 ranges and is limited to /16 block (65535 addresses).
string | $range | IP ranges to get the IPs within |
InvalidArgumentException | If input uses IPv6 |
InvalidArgumentException | If input range is too large |
|
static |
Returns the subnet of a given IP.
string | $ip |
|
static |
Converts a hexadecimal number to an IPv6 address in octet notation.
string | $ip_hex | Pure hex (no v6- prefix) |
|
static |
Converts a hexadecimal number to an IPv4 address in quad-dotted notation.
string | $ip_hex | Pure hex |
|
static |
Determine if a given IPv4/IPv6 address is in a given CIDR network.
string | $addr | The address to check against the given range. |
string | $range | The range to check the given address against. |
|
static |
Determines if an IP address is a list of CIDR a.b.c.d/n ranges.
string | $ip | the IP to check |
array | $ranges | the IP ranges, each element a range |
|
static |
Determine if a string is as valid IP address or network (CIDR prefix).
SIIT IPv4-translated addresses are rejected.
string | $ip | Possible IP address |
|
static |
Given a string, determine if it as valid IP in IPv4 only.
string | $ip | Possible IP address |
|
static |
Given a string, determine if it as valid IP in IPv6 only.
string | $ip | Possible IP address |
|
static |
Determine if an IP address really is an IP address, and if it is public, i.e.
not RFC 1918 or similar
string | $ip |
|
static |
Validate an IP address.
Ranges are NOT considered valid. SIIT IPv4-translated addresses are rejected.
string | $ip |
|
static |
Validate an IPv4 address.
Ranges are NOT considered valid.
string | $ip |
|
static |
Validate an IPv6 address.
Ranges are NOT considered valid. SIIT IPv4-translated addresses are rejected.
string | $ip |
|
static |
Validate an IP range (valid in either IPv4 OR IPv6; given with valid CIDR prefix or in explicit notation).
SIIT IPv4-translated addresses are rejected.
string | $ipRange |
|
static |
Convert a network specification in CIDR notation to an integer network and a number of bits.
string | $range | IP with CIDR prefix |
|
static |
Given a string range in a number of formats, return the start and end of the range in hexadecimal.
Formats are: 1.2.3.4/24 CIDR 1.2.3.4 - 1.2.3.5 Explicit range 1.2.3.4 Single IP
2001:0db8:85a3::7344/96 CIDR 2001:0db8:85a3::7344 - 2001:0db8:85a3::7344 Explicit range 2001:0db8:85a3::7344 Single IP
string | $range | IP range |
[false, false]
is returned
|
static |
Prettify an IP for display to end users.
This will make it more compact and lower-case.
string | $ip |
|
static |
Convert an IP into a verbose, uppercase, normalized form.
Both IPv4 and IPv6 addresses are trimmed. Additionally, IPv6 addresses in octet notation are expanded to 8 words; IPv4 addresses have leading zeros, in each octet, removed.
string | $ip | IP address in quad or octet form (CIDR or not). |
|
static |
Gets rid of unneeded numbers in quad-dotted/octet IP strings For example, 127.111.113.151/24 -> 127.111.113.0/24.
string | $range | IP address to normalize |
|
static |
Given a host/port string, like one might find in the host part of a URL per RFC 2732, split the hostname part and the port part and return an array with an element for each.
If there is no port part, the array will have false in place of the port. If the string was invalid in some way, false is returned.
This was easy with IPv4 and was generally done in an ad-hoc way, but with IPv6 it's somewhat more complicated due to the need to parse the square brackets and colons.
A bare IPv6 address is accepted despite the lack of square brackets.
string | $both | The string with the host (or IPv4/IPv6 address) and port |
|
static |
Return a zero-padded upper case hexadecimal representation of an IP address.
Hexadecimal addresses are used because they can easily be extended to IPv6 support. To separate the ranges, the return value from this function for an IPv6 address will be prefixed with "v6-", a non- hexadecimal string which sorts after the IPv4 addresses.
string | $ip | Quad dotted/octet IP address. |