CommonNetwork
in package
Holds common functions needed for translating different ipv4 stuff.
Tags
Table of Contents
Properties
- $myInterface : null|array<string, mixed>
- Primary interface.
- $myInterfaces : array<string, mixed>
- List of interfaces.
- $myHostname : null|string
- The hostrname of the host machine.
- $myIpaddresses : array<string, string>
- List of ip addresses for the host machine.
Methods
- cidrToIpArray() : array<int, string>
- Get the array of IP Addresses from a CIDR.
- cidrToNetmask() : null|string
- Convert a CIDR to a Netmask.
- cidrToNetwork() : null|string
- Get Network Address from a CIDR subnet.
- cidrToRange() : array<int, int|string|null>
- Get the Network's IP range from a CIDR.
- gethostname() : null|string
- Gets my hostname
- getMyInterfaces() : null|array<string, mixed>
- Gets the interface name of the given ip address, or all if none is given.
- getPrimaryIps() : null|array<string, string>
- Gets the primary ips for this host.
- ip2long() : int
- Converts an IP Address to a long integer.
- ipInCidr() : bool
- If the IP Address is in the Network.
- long2ip() : null|string
- Converts a long integer to an IP Address.
- netmaskToArray() : array<int, string>
- Return a list of IP Addresses for a netmask.
- netmaskToCidr() : int
- Convert Netmask to the CIDR.
- validateIP() : bool
- Validates a human readable ip address.
Properties
$myInterface
Primary interface.
public
null|array<string, mixed>
$myInterface
$myInterfaces
List of interfaces.
public
array<string, mixed>
$myInterfaces
= []
$myHostname
The hostrname of the host machine.
protected
null|string
$myHostname
= null
$myIpaddresses
List of ip addresses for the host machine.
protected
array<string, string>
$myIpaddresses
= []
Methods
cidrToIpArray()
Get the array of IP Addresses from a CIDR.
public
cidrToIpArray(string $network_cidr) : array<int, string>
e.g. 10.1.10.0/28 = array(10.1.10.0, 10.1.10.1, 10.1.10.2, 10.1.10.3)
Parameters
- $network_cidr : string
-
The network's CIDR.
Return values
array<int, string> —The list of ip addresses in the network.
cidrToNetmask()
Convert a CIDR to a Netmask.
public
cidrToNetmask(string $network_cidr) : null|string
e.g. 21 = 255.255.248.0
Parameters
- $network_cidr : string
-
The cidr to convert.
Return values
null|string —The Netmask.
cidrToNetwork()
Get Network Address from a CIDR subnet.
public
cidrToNetwork(string $network_cidr) : null|string
e.g. 10.0.2.56/21 = 10.0.0.0
Parameters
- $network_cidr : string
-
The network's cidr.
Return values
null|string —The IP Address
cidrToRange()
Get the Network's IP range from a CIDR.
public
cidrToRange(string $network_cidr[, bool $long = false ]) : array<int, int|string|null>
e.g. 10.1.10.0/28 = array(10.1.10.0, 10.1.10.3)
Parameters
- $network_cidr : string
-
The Network CIDR.
- $long : bool = false
-
If we should return the range as IP Addresses, or long integers.
Tags
Return values
array<int, int|string|null> —The first and last IP Address in the Network.
gethostname()
Gets my hostname
public
gethostname() : null|string
Return values
null|string —The hostname of the system this is ruynning on.
getMyInterfaces()
Gets the interface name of the given ip address, or all if none is given.
public
getMyInterfaces([null|string $ip = null ]) : null|array<string, mixed>
Parameters
- $ip : null|string = null
-
The ip address of the interface to get.
Return values
null|array<string, mixed> —Get the name of the interface.
getPrimaryIps()
Gets the primary ips for this host.
public
getPrimaryIps() : null|array<string, string>
Return values
null|array<string, string> —The primary ip address.
ip2long()
Converts an IP Address to a long integer.
public
ip2long(string $ip) : int
Parameters
- $ip : string
-
The IP Address.
Tags
Return values
int —The integer representing the IP Address.
ipInCidr()
If the IP Address is in the Network.
public
ipInCidr(string $ip, string $network_cidr) : bool
e.g. is 10.5.21.30 in 10.5.16.0/20 == true is 192.168.50.2 in 192.168.30.0/23 == false
Parameters
- $ip : string
-
The IP Address to check.
- $network_cidr : string
-
The Network CIDR to check.
Return values
bool —True if it's in the Network, False if it's not.
long2ip()
Converts a long integer to an IP Address.
public
long2ip(mixed|float|int $ip) : null|string
Parameters
- $ip : mixed|float|int
-
The Integer/float.
Return values
null|string —The IP Address.
netmaskToArray()
Return a list of IP Addresses for a netmask.
public
netmaskToArray(string $ipaddress, string $netmask) : array<int, string>
Parameters
- $ipaddress : string
-
The Ip Address.
- $netmask : string
-
The Netmask.
Return values
array<int, string> —The list of IP Addresses.
netmaskToCidr()
Convert Netmask to the CIDR.
public
netmaskToCidr(string $netmask) : int
e.g. 255.255.255.128 = 25
Parameters
- $netmask : string
-
The Netmask representing the Network.
Return values
int —The CIDR for the Network.
validateIP()
Validates a human readable ip address.
public
validateIP(string $ip) : bool
Parameters
- $ip : string
-
The IP Address to validate.
Return values
bool —True if the IP Address is valid, or false if not.