Feb 14, '11 07:30:00AM • Contributed by: macsadmn
The solution that I'm using to remote back to my laptop involves enabling VNC access on my laptop (System Preferences » Sharing » Remote Management » Computer Settings) and using a VNC viewer on the iPad (my choice, after trying many, is Remoter). There are two issues with doing this: (1) is that the IP address of my laptop changes from time to time and (2) when I'm out of the office, my iPad is not on the same LAN as my laptop, so Bonjour browsing doesn't do any good.
The script below, IP-Change-Notification.sh, takes care of those two issues by sending me an email every time my ethernet or wireless IP address changes. I then have the ability to look up my laptop IP address at any time by just checking my email on the iPad. Once I have the IP address, then I can open Remoter, paste in the IP, and connect. To get all this working, I simply put the script in an accessible folder (personally, I use ~/scripts). Then, I set up a cron task to run the script however often I want to check for a new IP.
My crontab has this entry to run it every 10 minutes:
############ */10 * * * * root bash /Users/yourshortname/scripts/IP-Change-Notification.sh ############
############
############
#!/bin/bash
PATH=/bin:/usr/bin:/sbin
# Written to email you if your computer has an IP address change. Invoke with a cron task.
# MANUALLY EDIT the line two below this one to list all email addresses that should receive notification of results.
# Only edit what is after the equals sign - addresses should be separated by spaces. Be sure to keep the single quotes intact.
tobenotified='joesnuffy@example.com'
touch /tmp/myip.txt
echo -e "en0:\n$(ifconfig en0 | grep -oP 'inet \K(\d{1,3}\.){3}\d{1,3}')\n\nen1:\n$(ifconfig en1 | grep -oP 'inet \K(\d{1,3}\.){3}\d{1,3}')" > /tmp/myip_temp.txt
if diff /tmp/myip_temp.txt /tmp/myip.txt &> /dev/null; then exit; else
mv /tmp/myip_temp.txt /tmp/myip.txt
cat /tmp/myip.txt | mail -s "IP Address Change on $(date '+%m/%d/%y @ %H:%M:%S')" $tobenotified -f ipchange@no-reply.com -F "IP CHANGE NOTIFICATION";
fi
############
############
One of my colleagues added the following lines above the if-statement
to track if his external IP address changes as well:
############
echo >> /tmp/myip_temp.txt
echo "Outside:" >> /tmp/myip_temp.txt
curl http://www.whatismyip.com/automation/n09230945.asp >> /tmp/myip_temp.txt
############
There may be better ways of doing this, so feel free to offer suggestions for improvement. At any rate, I hope some of you find this solution useful.
[crarko adds: I haven't tested this one. Let me know if there are errors in the script, please.]
