Binary IP

Tuesday 19th May, 2009

A little bit pointless perhaps, but just a quick little script to convert a users IP address into a binary IP - I can't even recall why I wrote this, but here it is anyway:

Code

// get users IP address
$ip = $_SERVER [ 'REMOTE_ADDR' ];

// convert IP into an array
$ip_array = explode('.', $ip);

// calculate binary version of IP address
$ip_binary = (16777216*$ip_array[0]) + (65536*$ip_array[1]) + (256*$ip_array[2]) + $ip_array[3];

// output the binary IP
echo $ip_binary;

Comments

Please login to comment on this page

back