Member-only story

Powerful PHP toolkit for handling IPv4 and IPv6 network addresses

Beck Moulton
2 min readMay 28, 2024

--

PHP library for handling network addresses (IPv4 and IPv6).

Installation

composer require s1lentium/iptools

Use

IP operation

IPv4

$ip = new IP('192.168.1.1');
echo $ip->version;// IPv4

IPv6

$ip = new IP('fc00::');
echo $ip->version; // IPv6

Resolve IP from integer, binary and hexadecimal

echo (string)IP::parse(2130706433); // 127.0.0.1
echo (string)IP::parse('0b11000000101010000000000100000001') // 192.168.1.1
echo (string)IP::parse('0x0a000001'); // 10.0.0.1

Or

echo (string)IP::parseLong(2130706433); // 127.0.0.1
echo (string)IP::parseBin('11000000101010000000000100000001'); // 192.168.1.1
echo (string)IP::parseHex('0a000001'); // 10.0.0.1

Convert IP to other formats

echo IP::parse('192.168.1.1')->bin // 11000000101010000000000100000001
echo IP::parse('10.0.0.1')->hex // 0a000001
echo IP::parse('127.0.0.1')->long // 2130706433

Other

  • maxPrefixLength Maximum numberof bits in address representation: 32 for IPv4 and 128 for IPv6.
  • octetsCountNumber of octets in IP Address: 4 for IPv4, 16 for IPv6

--

--

Beck Moulton
Beck Moulton

Written by Beck Moulton

Focus on the back-end field, do actual combat technology sharing Buy me a Coffee if You Appreciate My Hard Work https://www.buymeacoffee.com/BeckMoulton

No responses yet