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
BWHAHAHAH now I can follow it too and attack your home router.
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.
Yeah, because, you know... it's not already getting probed all day long by the script kiddiez.
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.
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.
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.
http://whatismyip.com/automation.asp and http://whatismyip.com/automation/n09230945.asp
I use email for notifying though and a Python script.
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
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
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".
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 :)
https://www.dnsomatic.com/ might be of interest to you.
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
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 :)
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.
Hi,
Nice Post. I read a lot of posts in this blog and found them very useful & interesting .
Regards,
Thomas Adora
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.
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. :)
Thanks for sharing this information, but I am curious. What technology did you use for the “interactive” ad?