class IpHelper (View source)

Methods

static int
getCidrBlockSize(int $prefix)

Calculate the block size for a given CIDR prefix (IPv4) Uses bit shifting instead of pow() for guaranteed int return type

static int
getCidrNetmask(int $cidr)

Calculate the netmask for a given CIDR prefix (IPv4)

static bool
isSubnetAligned(int $subnet, int $prefix)

Check if a subnet number is properly aligned for a given prefix

static string|null
getProposedIPv4(string $name, string $zoneName, string $suffix)

No description

static string|null
getProposedIPv6(string $name, string $zoneName, string $suffix)

No description

static string
expandIPv6(string $ip)

Expand an IPv6 address to its full form

static string
convertIPv6ToPTR(string $ip)

Convert an IPv6 address to its PTR record form

static string
buildReverseIPv4Domain(array $octets, int $cidr)

Build the reverse domain for an IPv4 address with appropriate CIDR handling

static string
getIPv6ReverseZone(string $networkPrefix)

Get IPv6 reverse zone for a network prefix

static string|null
networkToReverseZone(string $network)

Convert a network in CIDR notation to its reverse DNS zone name.

static string|null
shortenIPv6ReverseZone(string $reverseZone)

Convert IPv6 reverse zone (ip6.arpa) to shortened IPv6 notation

static string
displayZoneName(string $name)

Shorten a zone name for display, collapsing ip6.arpa reverse zones to IPv6 notation

static string|null
extractFirstIpFromMaster(string $master)

Extract the first valid IP address from a PowerDNS master field value

static string
shortenIPv6Address(string $address)

Shorten an IPv6 address to its compressed form

Details

static int getCidrBlockSize(int $prefix)

Calculate the block size for a given CIDR prefix (IPv4) Uses bit shifting instead of pow() for guaranteed int return type

Parameters

int $prefix

CIDR prefix (0-32)

Return Value

int

Block size (number of addresses in the subnet)

static int getCidrNetmask(int $cidr)

Calculate the netmask for a given CIDR prefix (IPv4)

Parameters

int $cidr

CIDR prefix (0-32)

Return Value

int

Netmask as integer

static bool isSubnetAligned(int $subnet, int $prefix)

Check if a subnet number is properly aligned for a given prefix

Parameters

int $subnet

Subnet number

int $prefix

CIDR prefix

Return Value

bool

True if aligned, false otherwise

static string|null getProposedIPv4(string $name, string $zoneName, string $suffix)

No description

Parameters

string $name
string $zoneName
string $suffix

Return Value

string|null

static string|null getProposedIPv6(string $name, string $zoneName, string $suffix)

No description

Parameters

string $name
string $zoneName
string $suffix

Return Value

string|null

static string expandIPv6(string $ip)

Expand an IPv6 address to its full form

Parameters

string $ip

IPv6 address, potentially in compressed form

Return Value

string

Expanded IPv6 address

static string convertIPv6ToPTR(string $ip)

Convert an IPv6 address to its PTR record form

Parameters

string $ip

IPv6 address

Return Value

string

PTR record form

static string buildReverseIPv4Domain(array $octets, int $cidr)

Build the reverse domain for an IPv4 address with appropriate CIDR handling

Parameters

array $octets

The IP address octets

int $cidr

The CIDR mask length

Return Value

string

The reverse domain name

static string getIPv6ReverseZone(string $networkPrefix)

Get IPv6 reverse zone for a network prefix

Parameters

string $networkPrefix

The IPv6 network prefix (e.g., "2001:db8:1:1")

Return Value

string

The reverse zone (e.g., "1.1.0.0.8.b.d.0.1.0.0.2.ip6.arpa")

static string|null networkToReverseZone(string $network)

Convert a network in CIDR notation to its reverse DNS zone name.

Accepts IPv4 networks ("192.168.1.0/24", or shorthand "192.168.1") and IPv6 networks ("2001:db8::/48"), returning the matching in-addr.arpa or ip6.arpa zone name aligned to the nearest octet (IPv4) or nibble (IPv6) boundary. Returns null when the input is not a usable network.

Parameters

string $network

Network address, optionally with a /prefix

Return Value

string|null

Reverse zone name, or null if not convertible

static string|null shortenIPv6ReverseZone(string $reverseZone)

Convert IPv6 reverse zone (ip6.arpa) to shortened IPv6 notation

Parameters

string $reverseZone

The reverse zone name (e.g., "1.0.0.0...ip6.arpa")

Return Value

string|null

Shortened IPv6 address or null if invalid

static string displayZoneName(string $name)

Shorten a zone name for display, collapsing ip6.arpa reverse zones to IPv6 notation

Parameters

string $name

The zone or record name

Return Value

string

Shortened IPv6 form for ip6.arpa names, otherwise the name unchanged

static string|null extractFirstIpFromMaster(string $master)

Extract the first valid IP address from a PowerDNS master field value

PowerDNS master field can contain various formats:

  • Single IP: "192.168.1.1"
  • Multiple IPs: "192.168.1.1,192.168.1.2"
  • IP with port: "192.168.1.1:5300" or "[2001:db8::1]:5300"
  • Hostname: "ns1.example.com"
  • Whitespace: " 192.168.1.1 "

This method extracts the first valid IP address, stripping ports and ignoring hostnames.

Parameters

string $master

The master field value from PowerDNS

Return Value

string|null

First valid IP address or null if none found

static string shortenIPv6Address(string $address)

Shorten an IPv6 address to its compressed form

Converts a full or partially expanded IPv6 address to its shortest representation using zero compression (::).

Parameters

string $address

IPv6 address in any valid format

Return Value

string

Shortened IPv6 address, or original string if not a valid IPv6