S1lentium / IPTools

PHP Library for manipulating network addresses (IPv4 and IPv6)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What's the difference?

imsheng opened this issue · comments

Iterate over Network IP adresses:

$network = Network::parse('192.168.1.0/24');
foreach($network as $ip) {
echo (string)$ip . '
';
}
192.168.1.0
...
192.168.1.255
Get Network hosts adresses as Range:

$hosts = Network::parse('192.168.1.0/24')->hosts // Range(192.168.1.1, 192.168.1.254);
foreach($hosts as $ip) {
echo (string)$ip . '
';
}
192.168.1.1
...
192.168.1.254

What's the difference?

I need to determine whether IP is in the range

First is iterating over all possible ips that covers network range;
Second is active host ips that are included in network;
https://en.wikipedia.org/wiki/Host_address