What’s my IP address?
June 17th, 2008 | by Sean |While working on the ZoneEdit update script, I did a survey of IP address checking techniques, 4 of them described below, and a fifth prototype which I think is the fastest and simplest IP address check on the Internet. I host several sites on servers in my home. I have a residential 1Mbit/s ADSL connection to the Internet, and my ISP assigns me an IP address by DHCP. In common with most (I suspect) people using ADSL, I have a combined ADSL modem and ethernet switch – a ‘router’, conecting my home LAN with the Internet (WAN).
On signing up with ZoneEdit.com, I read their page about automatic update agents for UNIX clients, where they suggest ddclient, zoneclient Dynamic DNS update utilities and a couple of command lines for updating Dynamic IP addresses using lynx (a text-based web browser) and wget (a Web download utility).
There are two essential parts to a Dynamic DNS update client:
- Detecting a change in your IP Address
- Updating the Dynamic DNS service
The utility software and the two command lines above all update the Dynamic DNS service the same way: by requesting ZoneEdit’s cunning URL:
http://dynamic.zoneedit.com/auth/dynamic.html?host=www.mydomain.com
The IP change discovery is much more interesting. ZoneEdit mentions routers with Dynamic DNS update support built in. Your router knows when the IP changes, as it runs a DHCP client. If your router has Dynamic DNS support built in, the DHCP client daemon should be able to respond directly to a new IP address and inform your Dynamic DNS service.
If the DHCP client daemon could update your Dynamic DNS service, this would be the perfect solution. I’ve had a few routers, and only one of them claimed to have this facility built in. It didn’t work. There are other methods, as ZoneEdit.com suggests, but all rely on polling some network feature to get the up to date IP address and compare it with the one last reported to the Dynamic DNS service.
1. IP Checking Web pages
ZoneEdit offers an IP checking web page at http://dynamic.zoneedit.com/checkip.html. You can check your IP address using a web browser on these services using an ordinary web browser, so click on the links and see first hand what gets reported to the Dynamic DNS update utilities. There are plenty of other sites offering similar pages: http://www.whatismyip.com is a pretty, but heavyweight page, while http://whatismyip.org is minimal.
ZoneEdit’s page is neither man nor beast compared to these other two. The undecorated IP address returned by whatismyip.org (or for automated clients at http://www.whatismyip.com/automation/n09230945.asp) can be captured by programs without effort. ZoneEdit’s page has labels, an unwanted hostname that doesn’t seem to work, and HTML tags.
While simple, this technique does require your utility to make a request on the Internet for data that is held locally. In addition, the data is requested by HTTP, adding some weight to what ought to be one of the simplest exchanges that could be made on a network.
2. From your router’s status page
This is a popular technique. You can, with most routers, administer them from your web browser. They often have a minimalistic web server running on their LAN interface, so http://192.168.1.1 (your router may have a different IP address) will often bring up a web page with a username and password form. The Dynamic DNS utilities often use this technique, requesting an authenticated router status page, and extracting the IP address from the returned HTML.
While this is a heavyweight technique in terms of authentication and amount of data transferred, the network traffic is all confined to your private network.
3. Simple Network Management Protocol
SNMP seems at first glance to be a great solution – you can just send a message to your router asking it what its interface IP addresses are. In practice, the two routers I’ve used this technique on have both become unresponsive after a few hours, and have stopped routing some time after that. I could not recommend this technique to anyone. I’d love to hear of a router that can cope with repeated SNMP requests – I’d buy one in a shot! Here’s a command line that will return the WAN IP address from two routers here. Remember, this command line may cause your router to stop routing and require a power off-on!
snmpwalk -v 1 -c public 192.168.1.1 IP-MIB::ipAdEntAddr
The good thing about the SNMP approach is that you confine your IP address discovery traffic to your private network, and (in my opinion) you’re using (if it works!) the right tool for the job.
4. Ping route recording
Ping offers the option to record the route taken by the ping packet. If you can find a host that reliably responds to pings on a network near you (a ping packet can only hold 9 route records, according to ping’s man page), you can extract your router’s WAN IP address from the route it took. For example, www.exabytes.com.my is a Malaysian hosting company in TM’s Internet Data Centre. See the route:
The 4th line of the output holds the IP address of my router – the ‘n’ option instructs ping not to convert IP addresses into names, the ‘R’ is for route recording, the ‘c 1’ limits ping to just a single ping. This is a super lightweight method that can be confined to a very local part of the Internet, if you choose your host carefully.
We’re currently using this method for our ZoneEdit.com zones, and it seems to be working well. A little bit too well! We ping our chosen host at 1 minute intervals, and see a few times a day that either the ping packet is lost, or occasionally, that the host is ‘unknown’. That’s not enough data to diagnose a network fault, but a sign that all is not as well as it could be.
The well-known best-kept secret: netcat
As I went through this survey, I used cURL to examine the data that is exchanged when querying public IP checking sites and router status pages. Aside from the occasional decorated page, a HTTP request seems needlessly bloated for the task of requesting a site echo your IP address. Your IP address isn’t part of the HTTP request, it’s available to the server when you open a socket to transfer your HTTP request. That lead me to think there ought to be a command line tool for opening sockets.
Telnet sprung to mind, and I use it from time to time to check open sockets on computers, but it’s not trivial to embed an interactive program like telnet in a shell script. After a little searching I turned up netcat. I have no idea why I didn’t know about netcat before – it’s a beautiful thing! It’s cat for URLs, but with a whole lot more functionality.
The cat part is what I really wanted: a utility that opens a socket on some site that echoes my IP address at me. I don’t know of such a site. WhatIsMyIP.org and similar don’t count – you have to send an HTTP request first. You can use cURL for that, but I wanted something even simpler. I couldn’t get my manpage mojo working well enough to work out how to write a shell script to echo IP addresses, so I tested netcat against a Java program IPEcho.java that echoes the source IP address of a connecting socket.
5. Fastest IP check on the Internet
This could all go terribly wrong, considering I’m using an ADSL connection for several sites, but i (edited March 2013 – this service is available at shipping-quote.net) If you want to test the power of netcat, just try a little:
nc shipping-quote.net 4447
My Slackware and Ubuntu distros both name netcat ‘nc’. [no longer available] is a machine on my LAN (edited March 2013 – this service is on my project shipping-quote.net), and 4447 is an open port to the Java IP Address echo program running on it. 4447 is what I have to type on my phone to get ‘ip’. Irrelevant, I know. On my LAN the IPEcho program is good for about 3000 reports per second, for about 800KiB/s of data transfer and 3% server load. If you don’t have netcat, you can probably use any web browser to see the output – try http://shipping-quote.net:4447. It’s not HTTP, but most web browsers will attempt to show the echoed text.
Please don’t test my ADSL connection to the limit – I’ll publish some statistics at a later date if the IPEcho service is popular. I’ll close the port again by 22nd July. Nobody in their right mind would run a service like this on a Dynamic IP address – I’m doing it because that’s all I’ve got.
4 Responses to “What’s my IP address?”
By Dido on Feb 19, 2009 | Reply
You can use http://www.ipaddressfinder.info as a web tool for public ip address lookup.
By Sean on Mar 5, 2009 | Reply
That’s a great example of what I don’t want! All I need is a service to discover my IP address, not buckets-full of spam and an epilepsy-inducing favicon! But hey, thanks for the link, it does help ‘situate’ the other methods.