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

Class: Net_IPv4

Source Location: /Net_IPv4-1.2/IPv4.php

Class Overview


Class to provide IPv4 calculations


Author(s):

Version:

  • 1.0

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 76]
Class to provide IPv4 calculations

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

  • Author: Eric Kilfoil <edk@ypass.net>
  • Version: 1.0
  • Access: public


[ Top ]


Class Variables

$bitmask =  false

[line 79]


Type:   mixed


[ Top ]

$broadcast =  ""

[line 82]


Type:   mixed


[ Top ]

$ip =  ""

[line 78]


Type:   mixed


[ Top ]

$long =  0

[line 83]


Type:   mixed


[ Top ]

$netmask =  ""

[line 80]


Type:   mixed


[ Top ]

$network =  ""

[line 81]


Type:   mixed


[ Top ]



Method Detail

atoh   [line 326]

void atoh( $addr)

Converts a dot-quad formmated IP address into a hexadecimal string

Parameters:

   $addr   — 

[ Top ]

calculate   [line 235]

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 115]

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 285]

void getNetLength( $netmask)


Parameters:

   $netmask   — 

[ Top ]

getNetmask   [line 276]

void getNetmask( $length)


Parameters:

   $length   — 

[ Top ]

getSubnet   [line 294]

void getSubnet( $ip, $netmask)


Parameters:

   $ip   — 
   $netmask   — 

[ Top ]

htoa   [line 340]

void htoa( $addr)

Converts a hexadecimal string into a dot-quad formatted IP address

Parameters:

   $addr   — 

[ Top ]

inSameSubnet   [line 303]

void inSameSubnet( $ip1, $ip2)


Parameters:

   $ip1   — 
   $ip2   — 

[ Top ]

ip2double   [line 353]

void ip2double( $ip)

Converts an IP address to a PHP double. Better than ip2long because a long in PHP is a signed integer.

Parameters:

   $ip   — 

[ Top ]

ipInNetwork   [line 370]

boolean 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 quad-dot representation of an IP address
string   $network   —  A string representing the network in CIDR format or a Net_IPv4 object.

[ Top ]

parseAddress   [line 174]

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 quad dot 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 97]

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 131]

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 10:15:59 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.