protected static inet_to_bits ( string $inet ) : string | ||
$inet | string | The in_addr representation of an IPv4 or IPv6 address |
return | string |
protected static function inet_to_bits($inet)
{
if (strlen($inet) == 4) {
$unpacked = unpack('A4', $inet);
} else {
$unpacked = unpack('A16', $inet);
}
$unpacked = str_split($unpacked[1]);
$binaryip = '';
foreach ($unpacked as $char) {
$binaryip .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
}
return $binaryip;
}