mercredi 24 juillet 2019

How to convert IPV6 to 15 chars length integer?

I need to convert IPV6 address to 15 chars length integer so I could use IP2LOCATION database?

This is the Database "IP2LOCATION-LITE-DB1.IPV6.CSV", that I downloaded from here http://download.ip2location.com/lite/

enter image description here

I try to use this function, but it gives me very long string:

function ipv6_numeric($ip) {
   $binNum = '';
   foreach (unpack('C*', inet_pton($ip)) as $byte) {
      $binNum .= str_pad(decbin($byte), 8, "0", STR_PAD_LEFT);
   }
   return base_convert(ltrim($binNum, '0'), 2, 10);
}

ipv6_numeric('fe80:0:0:0:202:b3ff:fe1e:8329')
return "338288524927261046600406220626806860202"



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire