I'm not the best with JavaScript. I was able to get a nice ipv62long()
function working in PHP awhile back and was able to help someone with their question regarding it. But posting to PHP just to get a result is pretty nasty in my opinion. Can a function like this be achieved in JavaScript? What functions am I looking for to achieve it? I've tried countless searches and they always feedback to PHP examples.
function ipv62long( $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 );
}
$ip = ipv62long(urldecode('2001%3a0%3a9d38%3a6abd%3a248d%3a2ee4%3a3f57%3afd26'));
echo $ip;
echo '<p>' . long2ip( $ip ) . '</p>';