docs/mindstab.net_blog/2012-01-23-finding-lost-com...

48 lines
1.8 KiB
Markdown
Raw Permalink Normal View History

# Finding "lost" computers on the web the homebrew way #
*Jan 23, 2012*
During the course of updating my home computer I rebooted it because of a kernel update. Later that week at work I went to connect to my home computer and discovered that it's dynamic IP had changed and it's DNS name was invalid.
So following common advice to "fix a problem two ways to prevent it in the future" I fixed the DNS, but I also wanted an automated way to track my computers when and if their IPs changed.
So the first thing I needed was shared place to store the IP information. Thinking about it I realized that Dropbox would work well for that. So all I needed was a simple script.
So the solution was to put a script that determined the IP of the computer in Dropbox and have cron on all the computers run it. Each user can call cron with
$ crontab -e
And I created a crontab directory that I could add more scripts to later if need be with and run them hourly with the following entry
0 * * * * cd /home/dan && run-parts Dropbox/cron
The script itself was a file called `getip` and it used whatsmyip.com's automation detection script.
**getip**
#!/bin/sh
wget -O /tmp/`hostname`.ip http://automation.whatismyip.com/n09230945.asp
tmp_file=/tmp/`hostname`.ip
dst_file=Dropbox/var/log/`hostname`.ip
if ! diff -q ${tmp_file} ${dst_file} > /dev/null ; then
`cp ${tmp_file} ${dst_file}`
fi
Then I just created `Dropbox/var/log` and installed the crontab on all my computers, and volia, homebrew IP tracking for all my compters accessible to me from anywhere.
## Comments ##
**garza** Says:
January 25th, 2012
or just use gnudip?
** Dan Ballard** Says:
January 27th, 2012
@garza Assuming you have a server to run it from, which while I do, not everyone may, and in this case, this with dropbox and whatismyip replaces.