' function Iptolong ($network)
{$networkLong = ';
if (Filter_var ($network, Filter_validate_ip, Filter_flag_ipv4)) {
$networkLong =base_convert (sprintf ("%u", Ip2long ($network)), 10, 2);
}else{
$networkPack = Inet_pton ($network);
$bits = 15; while ($bits >= 0) { $bin = sprintf("%08b", (ord($networkPack[$bits]))); $networkLong = $bin.$networkLong; $bits--; }} return $networkLong;
}
/ Get network address /
function GetSegment ($network, $mask) {
if (Filter_var ($network, Filter_validate_ip, Filter_flag_ipv4)) {
$IPV 4long=iptolong ($network);
$maskLong =str_pad (str_repeat (1, $mask), 32, 0);
$segment = $IPV 4Long & $maskLong;
return $segment;
}else{
$IPV 6long=iptolong ($network);
$maskLong =str_pad (str_repeat (1, $mask), 128, 0);
$segment = $IPV 6Long & $maskLong;
return $segment;
}
}
echo iptolong (' 106.32.59.244 ');
Echo '
';
echo getsegment (' 106.32.59.244 ', ' 29 ');
?> '
The network address calculated above is 106.32.59.244, why and calculate the inconsistency?
Reply content:
' function Iptolong ($network)
{$networkLong = ';
if (Filter_var ($network, Filter_validate_ip, Filter_flag_ipv4)) {
$networkLong =base_convert (sprintf ("%u", Ip2long ($network)), 10, 2);
}else{
$networkPack = Inet_pton ($network);
$bits = 15; while ($bits >= 0) { $bin = sprintf("%08b", (ord($networkPack[$bits]))); $networkLong = $bin.$networkLong; $bits--; }} return $networkLong;
}
/ Get network address /
function GetSegment ($network, $mask) {
if (Filter_var ($network, Filter_validate_ip, Filter_flag_ipv4)) {
$IPV 4long=iptolong ($network);
$maskLong =str_pad (str_repeat (1, $mask), 32, 0);
$segment = $IPV 4Long & $maskLong;
return $segment;
}else{
$IPV 6long=iptolong ($network);
$maskLong =str_pad (str_repeat (1, $mask), 128, 0);
$segment = $IPV 6Long & $maskLong;
return $segment;
}
}
echo iptolong (' 106.32.59.244 ');
Echo '
';
echo getsegment (' 106.32.59.244 ', ' 29 ');
?> '
The network address calculated above is 106.32.59.244, why and calculate the inconsistency?
Because it has to do with whether your machine is 32-bit or 64-bit.