{"id":30,"date":"2008-06-17T01:12:25","date_gmt":"2008-06-16T17:12:25","guid":{"rendered":"http:\/\/blog.lolyco.com\/sean\/?p=30"},"modified":"2013-03-09T04:56:30","modified_gmt":"2013-03-08T20:56:30","slug":"whats-my-ip-address","status":"publish","type":"post","link":"https:\/\/blog.lolyco.com\/sean\/2008\/06\/17\/whats-my-ip-address\/","title":{"rendered":"What&#8217;s my IP address?"},"content":{"rendered":"<p>While working on the <a title=\"ZoneEdit update script article\" href=\"http:\/\/blog.lolyco.com\/sean\/2008\/06\/13\/zoneeditcom-dynamic-dns-update-script\/\" target=\"_self\">ZoneEdit update script<\/a>, 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 &#8211; a &#8216;router&#8217;, conecting my home LAN with the Internet (WAN).<\/p>\n<p>On signing up with ZoneEdit.com, I read their <a title=\"ZoneEdit UNIX update clients\" href=\"http:\/\/zoneedit.com\/doc\/dynamic.html#faq3\" target=\"_blank\">page about automatic update agents for UNIX clients<\/a>, where they suggest <a title=\"ddclient at sourceforge\" href=\"http:\/\/ddclient.wiki.sourceforge.net\/\" target=\"_blank\">ddclient<\/a>, <a title=\"zoneclient at sourceforge\" href=\"http:\/\/zoneclient.sourceforge.net\/\" target=\"_blank\">zoneclient<\/a> Dynamic DNS update utilities and a couple of command lines for updating Dynamic IP addresses using <a title=\"Lynx at ISC\" href=\"http:\/\/lynx.isc.org\/\" target=\"_blank\">lynx<\/a> (a text-based web browser) and <a title=\"wget at GNU\" href=\"http:\/\/www.gnu.org\/software\/wget\/\" target=\"_blank\">wget<\/a> (a Web download utility).<\/p>\n<p>There are two essential parts to a Dynamic DNS update client:<\/p>\n<ol>\n<li>Detecting a change in your IP Address<\/li>\n<li>Updating the Dynamic DNS service<\/li>\n<\/ol>\n<p>The utility software and the two command lines above all update the Dynamic DNS service the same way: by requesting ZoneEdit&#8217;s cunning URL:<\/p>\n<p><code>http:\/\/dynamic.zoneedit.com\/auth\/dynamic.html?host=www.mydomain.com<\/code><\/p>\n<p>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.<\/p>\n<p>If the DHCP client daemon could update your Dynamic DNS service, this would be the perfect solution. I&#8217;ve had a few routers, and only one of them claimed to have this facility built in. It didn&#8217;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.<\/p>\n<h3>1. IP Checking Web pages<\/h3>\n<p>ZoneEdit offers an IP checking web page at <a href=\"http:\/\/dynamic.zoneedit.com\/checkip.html\">http:\/\/dynamic.zoneedit.com\/checkip.html<\/a>. 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: <a title=\"WhatIsMyIP.com IP address checker\" href=\"http:\/\/www.whatismyip.com\" target=\"_blank\">http:\/\/www.whatismyip.com<\/a> is a pretty, but heavyweight page, while <a title=\"WhatIsMyIP.org IP Check\" href=\"http:\/\/whatismyip.org\" target=\"_blank\">http:\/\/whatismyip.org<\/a> is minimal.<\/p>\n<p>ZoneEdit&#8217;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 <a title=\"WhatIsMyIP.com IP utility URL\" href=\"http:\/\/www.whatismyip.com\/automation\/n09230945.asp\" target=\"_blank\">http:\/\/www.whatismyip.com\/automation\/n09230945.asp<\/a>) can be captured by programs without effort. ZoneEdit&#8217;s page has labels, an unwanted hostname that doesn&#8217;t seem to work, and HTML tags.<\/p>\n<p>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.<\/p>\n<h3>2. From your router&#8217;s status page<\/h3>\n<p>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 <a title=\"Your router, maybe\" href=\"http:\/\/192.168.1.1\" target=\"_blank\">http:\/\/192.168.1.1<\/a> (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.<\/p>\n<p>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.<\/p>\n<h3>3. Simple Network Management Protocol<\/h3>\n<p>SNMP seems at first glance to be a great solution &#8211; you can just send a message to your router asking it what its interface IP addresses are. In practice, the two routers I&#8217;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&#8217;d love to hear of a router that can cope with repeated SNMP requests &#8211; I&#8217;d buy one in a shot! Here&#8217;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!<\/p>\n<p><code>snmpwalk -v 1 -c public 192.168.1.1 IP-MIB::ipAdEntAddr<\/code><\/p>\n<p>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&#8217;re using (if it works!) the right tool for the job.<\/p>\n<h3>4. Ping route recording<\/h3>\n<p>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&#8217;s man page), you can extract your router&#8217;s WAN IP address from the route it took. For example, <a title=\"Exabytes Malaysia\" href=\"http:\/\/www.exabytes.com.my\" target=\"_blank\">www.exabytes.com.my<\/a> is a Malaysian hosting company in TM&#8217;s Internet Data Centre. See the route:<\/p>\n<p><a href=\"http:\/\/blog.lolyco.com\/sean\/wp-content\/uploads\/2008\/06\/pingexabytes.jpeg\"><img loading=\"lazy\" decoding=\"async\" title=\"pingexabytes\" alt=\"Ping route recording\" src=\"http:\/\/blog.lolyco.com\/sean\/wp-content\/uploads\/2008\/06\/pingexabytes.jpeg\" width=\"300\" height=\"136\" \/><\/a><\/p>\n<p>The 4th line of the output holds the IP address of my router &#8211; the &#8216;n&#8217; option instructs ping not to convert IP addresses into names, the &#8216;R&#8217; is for route recording, the &#8216;c 1&#8217; 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.<\/p>\n<p>We&#8217;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 &#8216;unknown&#8217;. That&#8217;s not enough data to diagnose a network fault, but a sign that all is not as well as it could be.<\/p>\n<h3>The well-known best-kept secret: netcat<\/h3>\n<p>As I went through this survey, I used <a title=\"cURL ('see URL') at haxx.se\" href=\"http:\/\/curl.haxx.se\/\" target=\"_blank\">cURL<\/a> 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&#8217;t part of the HTTP request, it&#8217;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.<\/p>\n<p>Telnet sprung to mind, and I use it from time to time to check open sockets on computers, but it&#8217;s not trivial to embed an interactive program like telnet in a shell script. After a little searching I turned up <a title=\"netcat at debian\" href=\"http:\/\/packages.qa.debian.org\/n\/netcat.html\" target=\"_blank\">netcat<\/a>. I have no idea why I didn&#8217;t know about netcat before &#8211; it&#8217;s a beautiful thing! It&#8217;s cat for URLs, but with a whole lot more functionality.<\/p>\n<p>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&#8217;t know of such a site. WhatIsMyIP.org and similar don&#8217;t count &#8211; you have to send an HTTP request first. You can use cURL for that, but I wanted something even simpler. I couldn&#8217;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 <a title=\"IPEcho.java\" href=\"http:\/\/lolyco.com\/contributions\/IPEcho.java\" target=\"_self\">IPEcho.java<\/a> that echoes the source IP address of a connecting socket.<\/p>\n<h3>5. Fastest IP check on the Internet<\/h3>\n<p><del>This could all go terribly wrong, considering I&#8217;m using an ADSL connection for several sites, but i <\/del>(edited March 2013 &#8211; this service is available at <a href=\"http:\/\/www.shipping-quote.net\/about\/API.html#whatismyip\">shipping-quote.net<\/a>) If you want to test the power of netcat, just try a little:<\/p>\n<p><code>nc shipping-quote.net 4447<\/code><\/p>\n<p>My Slackware and Ubuntu distros both name netcat &#8216;nc&#8217;. <del datetime=\"2013-03-08T15:27:14+00:00\">[no longer available] is a machine on my LAN<\/del> (edited March 2013 &#8211; 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 &#8216;ip&#8217;. 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&#8217;t have netcat, you can probably use any web browser to see the output &#8211; try <a href=\"http:\/\/shipping-quote.net:4447\">http:\/\/shipping-quote.net:4447<\/a>. It&#8217;s not HTTP, but most web browsers will attempt to show the echoed text.<\/p>\n<p><del datetime=\"2013-03-08T15:27:14+00:00\">Please don&#8217;t test my ADSL connection to the limit &#8211; I&#8217;ll publish some statistics at a later date if the IPEcho service is popular. I&#8217;ll close the port again by 22nd July. Nobody in their right mind would run a service like this on a Dynamic IP address &#8211; I&#8217;m doing it because that&#8217;s all I&#8217;ve got.<\/del><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,17,11,3],"tags":[6,108,28,34,18],"class_list":["post-30","post","type-post","status-publish","format-standard","hentry","category-breaktime","category-broadband","category-google","category-software","tag-add-new-tag","tag-broadband","tag-dns","tag-network","tag-server"],"_links":{"self":[{"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/posts\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/comments?post=30"}],"version-history":[{"count":5,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/posts\/30\/revisions"}],"predecessor-version":[{"id":181,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/posts\/30\/revisions\/181"}],"wp:attachment":[{"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/media?parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/categories?post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/tags?post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}