PDA

View Full Version : HOWTO :: Quick Hack to Identify Dynamic IP Address


royong
22-04-2008, 11:12
Situation:
You have a newly installed Linux machine that is hooked on a Dynamic ADSL connection. You've done all the required port forwarding on your router to port forward all the required ports internally to your Linux machine. Now you are wondering, other than running a DynDns.Net or No-IP.Com service, what else can you do to find out the IP address assigned to you by your IP address? Well, here's what I did



cd /
mkdir /root/myscripts
cd /
cat > /root/myscripts/quick-ip-check <<"EOF"
#!/bin/sh
EMAILTO=xxx@gmail.com
COMMENTS=""
OUTPUT=`wget -q -O - http://checkip.dyndns.org:8245 | cut -f6 -d" " | cut -f1 -d"<"`
echo $COMMENTS | mail -s "`hostname` IP is $OUTPUT" $EMAILTO
EOF
chmod +x /root/myscripts/quick-ip-check
echo "07 * * * * root /root/myscripts/quick-ip-check" >> /etc/crontab
/root/myscripts/quick-ip-check


What will this do?
Basically it will query http://checkip.dyndns.org:8245 to find out the public IP address. It will then formulate an email to xxx@gmail.com with the hostname and public address every 7th minute of the hour i.e. 1607hrs, 1707hrs, 1807hrs etc. Of course, you will need to replace xxx@gmail.com with an appropriate email address. Hope this helps.

Can't I use Dnydns.Org or NO-IP.Com instead?
Of course you can. But they require you to register and run a custom script to update a hostname. For me, I find this to be very quick and easy, without any major requirements - just a bash shell and wget will do. It fits my purpose. Just register a gmail account and pipe all your output emails there. Its simple, lightweight and does the job :P