Skip to content

Instantly share code, notes, and snippets.

@samjaninf
Created September 26, 2018 19:17
Show Gist options
  • Select an option

  • Save samjaninf/0e684397b8a41d2583f28149fa8db879 to your computer and use it in GitHub Desktop.

Select an option

Save samjaninf/0e684397b8a41d2583f28149fa8db879 to your computer and use it in GitHub Desktop.
// https://inkplant.com/code/ipv6-to-number
<?php
function ipaddress_to_ipnumber($ipaddress) {
$pton = @inet_pton($ipaddress);
if (!$pton) { return false; }
$number = '';
foreach (unpack('C*', $pton) as $byte) {
$number .= str_pad(decbin($byte), 8, '0', STR_PAD_LEFT);
}
return base_convert(ltrim($number, '0'), 2, 10);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment