IP Class Reference

A collection of public static functions to play with IP address and IP blocks. More...

List of all members.

Static Public Member Functions

static isIPAddress ($ip)
 Given a string, determine if it as valid IP Unlike isValid(), this looks for networks too.
static isIPv6 ($ip)
static isIPv4 ($ip)
static IPv4toIPv6 ($ip)
 Given an IP address in dotted-quad notation, returns an IPv6 octet.
static toUnsigned6 ($ip)
 Given an IPv6 address in octet notation, returns an unsigned integer.
static sanitizeIP ($ip)
 Given an IPv6 address in octet notation, returns the expanded octet.
static toOctet ($ip_int)
 Given an unsigned integer, returns an IPv6 address in octet notation.
static HextoOctet ($ip_hex)
 Given a hexadecimal number, returns to an IPv6 address in octet notation.
static hexToQuad ($ip)
 Converts a hexadecimal number to an IPv4 address in octet notation.
static parseCIDR6 ($range)
 Convert a network specification in IPv6 CIDR notation to an integer network and a number of bits.
static parseRange6 ($range)
 Given a string range in a number of formats, return the start and end of the range in hexadecimal.
static isValid ($ip)
 Validate an IP address.
static isValidBlock ($ipblock)
 Validate an IP Block.
static isPublic ($ip)
 Determine if an IP address really is an IP address, and if it is public, i.e.
static toArray ($ipblock)
 Split out an IP block as an array of 4 bytes and a mask, return false if it can't be determined.
static toHex ($ip)
 Return a zero-padded hexadecimal representation of an IP address.
static toUnsigned ($ip)
 Given an IP address in dotted-quad/octet notation, returns an unsigned integer.
static toSigned ($ip)
 Convert a dotted-quad IP to a signed integer Returns false on failure.
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 canonicalize ($addr)
 Convert some unusual representations of IPv4 addresses to their canonical dotted quad representation.


Detailed Description

A collection of public static functions to play with IP address and IP blocks.

Definition at line 35 of file IP.php.


Member Function Documentation

static IP::canonicalize ( addr  )  [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.

Parameters:
$addr something that might be an IP address
Returns:
valid dotted quad IPv4 address or null

Definition at line 508 of file IP.php.

Referenced by wfGetIP().

static IP::HextoOctet ( ip_hex  )  [static]

Given a hexadecimal number, returns to an IPv6 address in octet notation.

Parameters:
$ip string hex IP
Returns:
string

Definition at line 158 of file IP.php.

static IP::hexToQuad ( ip  )  [static]

Converts a hexadecimal number to an IPv4 address in octet notation.

Parameters:
$ip string Hex IP
Returns:
string

Definition at line 176 of file IP.php.

Referenced by ApiQueryBlocks::execute().

static IP::IPv4toIPv6 ( ip  )  [static]

Given an IP address in dotted-quad notation, returns an IPv6 octet.

See http://www.answers.com/topic/ipv4-compatible-address IPs with the first 92 bits as zeros are reserved from IPv6

Parameters:
$ip quad-dotted IP address.
Returns:
string

Definition at line 72 of file IP.php.

static IP::isInRange ( addr,
range 
) [static]

Determine if a given IPv4/IPv6 address is in a given CIDR network.

Parameters:
$addr The address to check against the given range.
$range The range to check the given address against.
Returns:
bool Whether or not the given address is in the given range.

Definition at line 491 of file IP.php.

Referenced by Autopromote::checkCondition(), and Block::isWhitelistedFromAutoblocks().

static IP::isIPAddress ( ip  )  [static]

Given a string, determine if it as valid IP Unlike isValid(), this looks for networks too.

Parameters:
$ip IP address.
Returns:
string

Definition at line 42 of file IP.php.

Referenced by IPBlockForm::blockLogFlags(), SpecialContributions::contributionsSub(), IPBlockForm::doMassUserBlock(), DeletedContributionsPage::execute(), SpecialContributions::execute(), User::isBlockedGlobally(), and IPUnblockForm::showList().

static IP::isIPv4 ( ip  )  [static]

Definition at line 60 of file IP.php.

Referenced by User::inDnsBlacklist(), and Block::normaliseRange().

static IP::isIPv6 ( ip  )  [static]

Definition at line 51 of file IP.php.

Referenced by User::isIP(), and Block::normaliseRange().

static IP::isPublic ( ip  )  [static]

Determine if an IP address really is an IP address, and if it is public, i.e.

not RFC 1918 or similar Comes from ProxyTools.php

Definition at line 292 of file IP.php.

Referenced by wfGetIP().

static IP::isValid ( ip  )  [static]

Validate an IP address.

Returns:
boolean True if it is valid.

Definition at line 275 of file IP.php.

Referenced by Article::view().

static IP::isValidBlock ( ipblock  )  [static]

Validate an IP Block.

Returns:
boolean True if it is valid.

Definition at line 283 of file IP.php.

static IP::parseCIDR ( range  )  [static]

Convert a network specification in CIDR notation to an integer network and a number of bits.

Returns:
array(string, int)

Definition at line 408 of file IP.php.

Referenced by ApiQueryBlocks::execute(), and wfParseCIDR().

static IP::parseCIDR6 ( range  )  [static]

Convert a network specification in IPv6 CIDR notation to an integer network and a number of bits.

Returns:
array(string, int)

Definition at line 192 of file IP.php.

static IP::parseRange ( range  )  [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

Returns:
array(string, int)

Definition at line 446 of file IP.php.

Referenced by Block::initialiseRange().

static IP::parseRange6 ( range  )  [static]

Given a string range in a number of formats, return the start and end of the range in hexadecimal.

For IPv6.

Formats are: 2001:0db8:85a3::7344/96 CIDR 2001:0db8:85a3::7344 - 2001:0db8:85a3::7344 Explicit range 2001:0db8:85a3::7344/96 Single IP

Returns:
array(string, int)

Definition at line 229 of file IP.php.

static IP::sanitizeIP ( ip  )  [static]

Given an IPv6 address in octet notation, returns the expanded octet.

IPv4 IPs will be trimmed, thats it...

Parameters:
$ip octet ipv6 IP address.
Returns:
string

Definition at line 115 of file IP.php.

Referenced by Block::__construct(), User::getName(), Title::secureAndSplit(), and IPUnblockForm::showList().

static IP::toArray ( ipblock  )  [static]

Split out an IP block as an array of 4 bytes and a mask, return false if it can't be determined.

Parameters:
$ip string A quad dotted/octet IP address
Returns:
array

Definition at line 332 of file IP.php.

static IP::toHex ( ip  )  [static]

Return a zero-padded 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.

Parameters:
$ip Quad dotted/octet IP address.
Returns:
hexidecimal

Definition at line 354 of file IP.php.

Referenced by ApiQueryBlocks::execute(), Block::loadRange(), and IPUnblockForm::showList().

static IP::toOctet ( ip_int  )  [static]

Given an unsigned integer, returns an IPv6 address in octet notation.

Parameters:
$ip integer IP address.
Returns:
string

Definition at line 140 of file IP.php.

Referenced by Block::normaliseRange().

static IP::toSigned ( ip  )  [static]

Convert a dotted-quad IP to a signed integer Returns false on failure.

Definition at line 392 of file IP.php.

static IP::toUnsigned ( ip  )  [static]

Given an IP address in dotted-quad/octet notation, returns an unsigned integer.

Like ip2long() except that it actually works and has a consistent error return value. Comes from ProxyTools.php

Parameters:
$ip Quad dotted IP address.
Returns:
integer

Definition at line 369 of file IP.php.

Referenced by Block::normaliseRange().

static IP::toUnsigned6 ( ip  )  [static]

Given an IPv6 address in octet notation, returns an unsigned integer.

Parameters:
$ip octet ipv6 IP address.
Returns:
string

Definition at line 98 of file IP.php.

Referenced by Block::normaliseRange().


The documentation for this class was generated from the following file:

Generated on Sat Sep 5 02:08:39 2009 for MediaWiki by  doxygen 1.5.9