I occasionally wish to know the IP address of my home Cable Modem or DSL connection but don't really care if it's available in DNS or not. It occurred to me that if I could programmatically detect the IP change, I'd be able to notify myself via Twitter.

At first, I wanted a simple web service that'd tell me my IP address--something like WhatIsMyIP.com but an API suitable for simple scripting.

Not finding anything, I created this massive PHP script instead and hosted it on my server:

That made it easy to write a simple bash shell script that can be run from cron every few minutes. It uses curl to hit that script and compares the result with the previous result (stored in ~/.last_ip). If they differ it updates the file and tells twitter, again using curl.

Of course, I had to create that new twitter account and then follow it in my main account. But, hey, that wasn't so hard. Now I have a Web 2.0ish social dynamic DNS thingy that uses Twitter.

Aren't I cool and buzzword compliant?!

Posted by jzawodn at December 30, 2008 08:42 AM

Reader Comments
# Tom Printy said:

BWHAHAHAH now I can follow it too and attack your home router.

on December 30, 2008 08:55 AM
# PanMan said:

Cool application :).
However I do wonder if it wouldn't be just as much (or less) work to post the IP to a Dynamic IP service (or even use the API of a normal DNS provider), than to use twitter. And then connecting to home would be one step less (just type home.zawodny.com wherever you wanted to connect), instead of first looking up your home IP.
Still, it's interesting to see what people come up with if there is a simple public message system.

on December 30, 2008 08:58 AM
# Jeremy Zawodny said:

Yeah, because, you know... it's not already getting probed all day long by the script kiddiez.

on December 30, 2008 08:59 AM
# jeremiah said:

Your router probably has support for dynamic DNS already. That would have been easier. But not as entertaining or as fun or as "Web 2.0" whatever that means.

on December 30, 2008 09:14 AM
# Zach Leatherman said:

Can you please post a Windows batch file port I can use with Windows Scheduler and my Pownce account?

Just kidding. Enjoyed reading your post.

on December 30, 2008 09:26 AM
# Rob said:

I thought this was an interesting experiment using Twitter. I personally can't find a use for Twitter but, it's good to see the service used in other creative ways.

on December 30, 2008 11:28 AM
# Edgars said:

http://whatismyip.com/automation.asp and http://whatismyip.com/automation/n09230945.asp

I use email for notifying though and a Python script.

on December 30, 2008 12:38 PM
# Chris W said:

You didn't really need to post your IP to a Twitter account, since you clearly have your own server (or slice).

Easier than crafting and using the ip.php script, you could make a home.php script that simply displays the last known IP address for your home.

Why did you take the steps to set up an additional Twitter account and post updates to it? Don't get me wrong ... I don't want to knock what you've done. I'm a fan of all hacks. I'm just wondering if there's more utility to the extra steps than meets the eye.

Peace!
~CW

on December 30, 2008 04:39 PM
# Charles Hooper said:

Good stuff, but just to avoid some flak (and since it's easy to do so), you should probably protect your updates.

On Twitter: Settings -> Check "Protect my updates" -> Save

on December 30, 2008 04:49 PM
# Richard Bronosky said:

I'd take this a step farther and offload more of the work. I made a Google App Engine app to return your IP in JSON which is useful for obvious reasons. You could make an app (G.A.E.) that your cron job could hit and pass your twitter username and password. The app would use the twitter API to get your last posted IP, compare it to the new one, and repost on delta. You wouldn't have to host the server side piece, have the .last_ip local, or have a "complicated" script locally. The really cool part is that you could publish it and allow anyone use it. Then it would be a true "Web 2.0 no way to monetize social application".

on December 30, 2008 05:36 PM
# Dragan Bajcic said:

I use no-ip.com, and i have something like myhomemachine.no-ip.org, they have clients for win, linux, and mac.

Though, it's not so web2.0ish as your twitter solution :)

on December 31, 2008 02:44 AM
# Jay Janssen said:

https://www.dnsomatic.com/ might be of interest to you.

on December 31, 2008 09:27 AM
# Richard Toohey said:

You should try and get in the habit of using long tags in PHP - not doing so *will* bite you one day when you least want it - so

on January 1, 2009 02:04 AM
# Jonathon Hill said:

LOL! I thought this was for real... but you did have me scratching my head as to *why* anyone would even want such a thingy :)

on January 4, 2009 07:12 PM
# JD said:

You could also have your script e-mail you the new IP each time it changes. My IP doesn't change very often, so I might get a new one e-mailed once every few months. If I find that my current IP isn't working, I just check my email for the new one. This is one way to keep it private.

on January 5, 2009 09:51 AM
# Cheap Web Host said:

Hi,
Nice Post. I read a lot of posts in this blog and found them very useful & interesting .
Regards,
Thomas Adora

on January 9, 2009 05:31 PM
# Sean said:

Oh very nice. I use ping route recording to watch my IP address. Seems to work great, though one ISP I used recently 'blackholed' everything except browsing traffic.

on February 22, 2009 08:16 PM
# dinty said:

To Lookup IP Address --- www.ipaddressfinder.info

on March 26, 2009 11:16 PM
# shepd said:

You could try this:

#!/bin/sh

T_USER=twitter_username
T_PASS=twitter_password
T_URL=http://twitter.com/statuses/update.xml

OLDIP="1"
NEWIP=`/sbin/ifconfig eth0 | /bin/sed -n "/inet addr/ s/^.\+inet addr\:\([0-9.]\+\).\+$/\1/g p"`

while [ 1 ]; do
if [ $OLDIP != $NEWIP ]; then
curl -s -o /dev/null -u $T_USER:$T_PASS -d status="$NEWIP" $T_URL
OLDIP=$NEWIP
else
NEWIP=`/sbin/ifconfig eth0 | /bin/sed -n "/inet addr/ s/^.\+inet addr\:\([0-9.]\+\).\+$/\1/g p"`
fi
/bin/sleep 60
done

No temp files, no webserver, no php required. Just remember to background it if you run it on boot. :)

on May 8, 2009 11:28 AM
# pai gow said:

Thanks for sharing this information, but I am curious. What technology did you use for the “interactive” ad?

on June 10, 2009 10:14 PM
Disclaimer: The opinions expressed here are mine and mine alone. My current, past, or previous employers are not responsible for what I write here, the comments left by others, or the photos I may share. If you have questions, please contact me. Also, I am not a journalist or reporter. Don't "pitch" me.

 

Privacy: I do not share or publish the email addresses or IP addresses of anyone posting a comment here without consent. However, I do reserve the right to remove comments that are spammy, off-topic, or otherwise unsuitable based on my comment policy. In a few cases, I may leave spammy comments but remove any URLs they contain.