IpHelper
class IpHelper (View source)
Methods
Calculate the block size for a given CIDR prefix (IPv4) Uses bit shifting instead of pow() for guaranteed int return type
Calculate the netmask for a given CIDR prefix (IPv4)
Check if a subnet number is properly aligned for a given prefix
No description
No description
Expand an IPv6 address to its full form
Convert an IPv6 address to its PTR record form
Build the reverse domain for an IPv4 address with appropriate CIDR handling
Get IPv6 reverse zone for a network prefix
Convert a network in CIDR notation to its reverse DNS zone name.
Convert IPv6 reverse zone (ip6.arpa) to shortened IPv6 notation
Shorten a zone name for display, collapsing ip6.arpa reverse zones to IPv6 notation
Extract the first valid IP address from a PowerDNS master field value
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
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.
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.
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
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.
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 (::).