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 http://example.com/ping.php
<?php $ip = $_SERVER['REMOTE_ADDR']; $handle = fopen("./ip.txt", 'w'); fwrite($handle, $ip); fclose($handle); echo $ip;
<?php echo file_get_contents("ip.txt");
touch ip.txt chmod a+w ip.txt
Simply browse to http://example.com/pong.php to get the last known IP address.
Latest posts by Thomas Hunter II (see all)
- Upgrading from an XPS 13 (9350) to a Carbon X1 5th Gen - 2017-10-03
- What have I been up to? Late 2017 Edition - 2017-09-28
- Is it time to replace REST with RPC? - 2017-09-27