Posted by & filed under Linux.

After moving to my new apartment, it was time to dust off the old Linksys router I had lying around. This thing has been hacked to run the latest DD-WRT that it could handle.

My network address changes occasionally, and I didn’t want to setup any dyndns accounts to keep track of the IP and have it resolve to a hostname. Honestly, just being able to get the last IP address is good enough for me.

So, I came up with this script that I run on one of my websites which listens for HTTP requests. When it gets one, it simply logs the IP to a file and spits it back out to the client.

Then, whenever I want to grab the IP address of the home network, I just hit another URL to grab the IP. The script is requested from my router every hour.


Open your DD-WRT settings, go to Administration | Management, and scroll down till you see the section on CRON. You can add the following rule to have your router grab the file every hour:

*/60 * * * * root wget
Screen Shot 2013-05-16 at 11.01.28 PM


$handle = fopen("./ip.txt", 'w');
fwrite($handle, $ip);
echo $ip;


echo file_get_contents("ip.txt");


touch ip.txt
chmod a+w ip.txt

Obtaining IP

Simply browse to to get the last known IP address.

Thomas Hunter II

Thomas is the author of Advanced Microservices and a prolific public speaker with a passion for reducing complex problems into simple language and diagrams. His career includes working at Fortune 50's in the Midwest, co-founding a successful startup, and everything in between.
(Visited 1,252 times, 10 visits today)
  • Hi,

    an alternative is to user DynDNS service. DD-WRT support this natively:

    You have a nice blog. Thanks for sharing.

  • Steve

    SO excellent. I’ve been using various DDNS providers for years, mostly in recent years, but it honestly has just never dawned on me to just roll my own. Clever. Thank you!

  • John Bob

    I’m retrieving the ip.txt directly, without the need for another php script.
    Additionally i have added a timestamp with:

    fwrite($handle, $ip);
    // prints something like: Wed, 25 Sep 2013 15:28:57 -0700
    fwrite($handle, date(DATE_RFC2822));

    so i can see if the ip has been updated recently and my internet is therefore up