<?php
function ipv4Breakout ($ip_address, $ip_nmask) {
$hosts = array();
//convert ip addresses to long form
$ip_address_long = ip2long($ip_address);
$ip_nmask_long = ip2long($ip_nmask);
//caculate network address
$ip_net = $ip_address_long & $ip_nmask_long;
//caculate first usable address
$ip_host_first = ((~$ip_nmask_long) & $ip_address_long);
$ip_first = ($ip_address_long ^ $ip_host_first) + 1;
//caculate last usable address
$ip_broadcast_invert = ~$ip_nmask_long;
$ip_last = ($ip_address_long | $ip_broadcast_invert) - 1;
//caculate broadcast address
$ip_broadcast = $ip_address_long | $ip_broadcast_invert;
foreach (range($ip_first, $ip_last) as $ip) {
array_push($hosts, $ip);
}
$block_info = array(array("network" => "$ip_net"),
array("first_host" => "$ip_first"),
array("last_host" => "$ip_last"),
array("broadcast" => "$ip_broadcast"),
$hosts);
return $block_info;
}
print_r ipv4Breakout ('96.4.3.0', '255.255.255.0');
- Output for 5.5.24 - 5.5.30, 5.6.8 - 5.6.15
- Parse error: syntax error, unexpected 'ipv4Breakout' (T_STRING) in /in/Yestf on line 36
Process exited with code 255.
preferences:
166.34 ms | 1395 KiB | 22 Q