1 minute read

An IP address is a unique number which identifies a machine on a network.

On the Internet IP addresses are allocated in blocks to ISPs in each country by regional registries, making it possible to identify which country an IP address originated in.

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 something like ipconfig will only return your LAN IP address (something like 192.168.0.1).

That is why many “what is my ip” websites exist, making it easy for you to lookup your external IP address.

My favourite IP lookup service has been for a long time one run by NASDAQ-100 content delivery specialists “Akamai Technologies”:

It’s brilliant in its simplicity but it’s not very pretty.

We decided to do something different. We made a pretty “What is my IP address?” lookup:

Part of its beauty is that the audience its aimed at is able to quickly read and understand the information at a glance, without any prompts. While those who don’t understand it can marvel at its pretty form and ponder over its usefulness.

The other part of its beauty is that it’s highly parsable.

It’s easy to parse the IP address, mainly 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.deaduseful.com’,1); echo trim($h[‘Location’],’/’); ?>

However, this method isn’t very portable, so may not be suitable 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.deaduseful.com’));?>

The brilliance in this little snippet is that it will work with any useful “What is my IP?” lookup website.

So as you can see, it’s really easy to work with as a pretty API as well.

Beyond the IP address, you only need to look at the source code to understand that it’s easy to parse the other details.

I hope you found this useful!

Comments