IP visual

Post date: Jan 27, 2012 5:39:14 PM

Via phurix labs: What is my IP?, which results in a very surprising visual!

An IP address uniquely identifies a machine on a network. Internet IP addresses are allocated in blocks to ISPs in each country by regional registries. Often, if you are connected to the Internet behind a router, you share an online IP address with everyone else on your local area network (LAN). Sometimes you need to know your external IP address and using ipconfig will only return your LAN IP address e.g. 192.168.0.1.

Content delivery specialists Akamai Technologies have an excellent IP address look up, whatismyip.akamai.com. Phurix did something different. They made a pretty “What is my IP address?” lookup:

It is attractive, and according to phurix, it’s highly parsable.

"It’s easy to parse the IP address, because the presentation (CSS) is separate from the markup (HTML), but also because of the headers. Here’s a short demonstration to show how you can use the headers to get the IP address using this tool:

<?php $h=get_headers(‘http://ip.phurix.net’,1); echo trim($h['Location'],’/'); ?>

However, this method isn’t very portable, and is unsuitable if you’re checking against multiple sources at once. So instead, we can also demonstrate using a simple regular expression and a function that can get http contents (such as file_get_contents() in PHP).

<?php echo preg_replace(‘/.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*/s’,'$1′,file_get_contents(‘http://ip.phurix.net’));?>

This little snippet will work with any useful “What is my IP?” lookup website. Beyond the IP address, you only need to look at the source code to understand that it’s easy to parse the other details."