Net_IPv4
[ class tree: Net_IPv4 ] [ index: Net_IPv4 ] [ all elements ]

Class: Net_IPv4

Source Location: /Net_IPv4-1.3.4/Net/IPv4.php

Class Overview


Class to provide IPv4 calculations


Author(s):

Version:

  • CVS: @package_version@

Copyright:

  • 1997-2005 The PHP Group

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 90]
Class to provide IPv4 calculations

Provides methods for validating IP addresses, calculating netmasks, broadcast addresses, network addresses, conversion routines, etc.



[ Top ]


Class Variables

$bitmask =  false

[line 94]


Type:   mixed


[ Top ]

$broadcast =  ""

[line 97]


Type:   mixed


[ Top ]

$ip =  ""

[line 93]


Type:   mixed


[ Top ]

$long =  0

[line 98]


Type:   mixed


[ Top ]

$netmask =  ""

[line 95]


Type:   mixed


[ Top ]

$network =  ""

[line 96]


Type:   mixed


[ Top ]



Method Detail

atoh   [line 378]

mixed atoh( string $addr)

Converts a dot-quad formatted IP address into a hexadecimal string
  • Return: false if invalid IP and hexadecimal representation as string if valid

Parameters:

string   $addr   —  IP-adress in dot-quad format

[ Top ]

calculate   [line 265]

mixed calculate( )

Calculates network information based on an IP address and netmask.

Fully populates the object properties based on the IP address and netmask/bitmask properties. Once these two fields are populated, calculate() will perform calculations to determine the network and broadcast address of the network.

  • Return: true if no errors occured, otherwise PEAR_Error object

[ Top ]

check_ip   [line 136]

bool check_ip( string $ip)

Validate the syntax of the given IP address (compatibility)

This function is identical to Net_IPv4::validateIP(). It is included merely for compatibility reasons.

  • Return: true if syntax is valid, otherwise false

Parameters:

string   $ip   —  IP address

[ Top ]

getNetLength   [line 323]

void getNetLength( $netmask)


Parameters:

   $netmask   — 

[ Top ]

getNetmask   [line 310]

void getNetmask( $length)


Parameters:

   $length   — 

[ Top ]

getSubnet   [line 336]

void getSubnet( $ip, $netmask)


Parameters:

   $ip   — 
   $netmask   — 

[ Top ]

htoa   [line 395]

mixed htoa( string $addr)

Converts a hexadecimal string into a dot-quad formatted IP address
  • Return: false if invalid IP and dot-quad formatted IP as string if valid

Parameters:

string   $addr   —  IP-adress in hexadecimal format

[ Top ]

inSameSubnet   [line 349]

void inSameSubnet( $ip1, $ip2)


Parameters:

   $ip1   — 
   $ip2   — 

[ Top ]

ip2double   [line 414]

float ip2double( string $ip)

Converts an IP address to a PHP double. Better than ip2long because a long in PHP is a signed integer.
  • Return: IP adress as double - positive value unlike ip2long

Parameters:

string   $ip   —  dot-quad formatted IP adress

[ Top ]

ipInNetwork   [line 434]

bool ipInNetwork( string $ip, string $network)

Determines whether or not the supplied IP is within the supplied network.

This function determines whether an IP address is within a network. The IP address ($ip) must be supplied in dot-quad format, and the network ($network) may be either a string containing a CIDR formatted network definition, or a Net_IPv4 object.

  • Return: true if the IP address exists within the network

Parameters:

string   $ip   —  A dot quad representation of an IP address
string   $network   —  A string representing the network in CIDR format or a Net_IPv4 object.

[ Top ]

parseAddress   [line 201]

object true parseAddress( $address, string $ip)

Parse a formatted IP address

Given a network qualified IP address, attempt to parse out the parts and calculate qualities of the address.

The following formats are possible:

[dot quad ip]/[ bitmask ] [dot quad ip]/[ dot quad netmask ] [dot quad ip]/[ hex string netmask ]

The first would be [IP Address]/[BitMask]: 192.168.0.0/16

The second would be [IP Address] [Subnet Mask in dot quad notation]: 192.168.0.0/255.255.0.0

The third would be [IP Address] [Subnet Mask as Hex string] 192.168.0.0/ffff0000

Usage:

$cidr = '192.168.0.50/16'; $net = Net_IPv4::parseAddress($cidr); echo $net->network; // 192.168.0.0 echo $net->ip; // 192.168.0.50 echo $net->broadcast; // 192.168.255.255 echo $net->bitmask; // 16 echo $net->long; // 3232235520 (long/double version of 192.168.0.50) echo $net->netmask; // 255.255.0.0

  • Return: if syntax is valid, otherwise false

Parameters:

string   $ip   —  IP address netmask combination
   $address   — 

[ Top ]

validateIP   [line 115]

bool validateIP( string $ip)

Validate the syntax of the given IP adress

Using the PHP long2ip() and ip2long() functions, convert the IP address from a string to a long and back. If the original still matches the converted IP address, it's a valid address. This function does not allow for IP addresses to be formatted as long integers.

  • Return: true if syntax is valid, otherwise false

Parameters:

string   $ip   —  IP address in the format x.x.x.x

[ Top ]

validateNetmask   [line 155]

bool validateNetmask( string $netmask)

Validate the syntax of a four octet netmask

There are 33 valid netmask values. This function will compare the string passed as $netmask to the predefined 33 values and return true or false. This is most likely much faster than performing the calculation to determine the validity of the netmask.

  • Return: true if syntax is valid, otherwise false

Parameters:

string   $netmask   —  Netmask

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:39:03 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.