php-ip icon indicating copy to clipboard operation
php-ip copied to clipboard

Get all IP's in block according to netmask

Open z3ro opened this issue 2 years ago • 1 comments

Hello i want to calculate and echo all the ips according to IP & netmask for example 127.0.0.1 netmask 255.255.255.192 i want to do for loop on all the block. how it could be !

z3ro avatar Dec 06 '23 15:12 z3ro

For example:

$block = new PhpIP\IPv4Block("127.0.0.0/255.255.255.192");

foreach ($block as $ip) {
    print "ip: $ip\n";
}

Outputs:

ip: 127.0.0.0
ip: 127.0.0.1
ip: 127.0.0.2
....
ip: 127.0.0.62
ip: 127.0.0.63

haegar avatar Dec 06 '23 17:12 haegar