Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Remote Control Your DHCP Connected Laptop from Your iPad UNIX
I work in a growing school district with multiple campuses. Each week I find myself in different buildings for one reason or another. Like many people, I've realized it's much handier to grab my iPad and go, rather than lug the laptop. However, there are times when it's necessary to access information or applications on my laptop when I'm out and about.

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

############
Note: I run the script as root to ensure it runs even if I'm not logged in. Here's the body of 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

############
This has worked very well for me for a few months now. I've even started taking my iPad home instead of the laptop. Once on my home connection, I just use VPN to connect back to the network and then remote to my laptop if necessary.

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.]
    •    
  • Currently 3.86 / 5
  You rated: 4 / 5 (7 votes cast)
 
[7,102 views]  

Remote Control Your DHCP Connected Laptop from Your iPad | 26 comments | Create New Account
Click here to return to the 'Remote Control Your DHCP Connected Laptop from Your iPad' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: tofergregg on Feb 14, '11 07:43:50AM

Nice hint. This has been said for other VNC-based hints before, but LogMeIn does a great job of punching through any firewalls and being available anywhere. The iPad app (I think it's about $25) is great, too.



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: Unsoluble on Feb 14, '11 09:19:13AM

LogMeIn works, and is an option, but I found the client software to be terrible in practice. Much, much better is iTeleport (and it's also cheaper).



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: auco on Feb 14, '11 08:24:07AM

couldn't you use a dyndns service? that might be handier than getting lots of emails...



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: macsadmn on Feb 14, '11 08:31:43AM

I don't believe that services like dyndns will report any changes of private (internal) IP addresses - which is mainly what this hint is aiming at.



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: j-beda on Feb 15, '11 04:46:04AM

The last time I used dyndns they were able to do both internal (private) and external (public) IP addresses (at least for the DNSUpdate.app client from http://www.dnsupdate.org/ which seems to be at the same version I was using). I had it set up to maintain two dynamic addresses, one for example called myname-private.dyndns.org and one called myname-public.dyndns.org allowing me to ssh into my server and then ssh from there into the individual machine.

For this application, the http://www.dnsupdate.org/ software could be installed on the laptop and set both of these addresses.

Once I realized I could use the router to assign static addresses via DHCP, the need for this functionality has decreased. Combined with "back-to-my-mac" on the Time Capsule and the fact that I carry my laptop around a lot means I have less need to access the "internals" of the home network these days.



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: macsadmn on Feb 15, '11 06:27:51AM

In that case, dyndns could be a good solution for a home network, but probably not-so-much for a corporate style network, which can be a bit more complex :-)



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: j-beda on Feb 15, '11 08:46:31AM

the dydns client can record and send the machine's current IP address, which is exactly what the hint is doing - regardless of the complexiity of the network



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: macsadmn on Feb 15, '11 12:54:30PM

I'm always interested in alternative ways to do things, so I downloaded both the client app from http://www.dnsupdate.org/ & the one from https://www.dyndns.com/ . I cannot see that either app has a feature for email notification. In fact, I only find mention of it on the dyndns forums, which seem to indicate that feature existed, but has since has been removed. It sounds like it may be possible if you sign up with DNS-O-Matic in conjunction with dyndns. Of course, there is always the possibility that I may be overlooking something. Nonetheless, with all the registrations and contacting external sites, I think I'll just stick with a script that I can control and update as needed. Thank you though for your comments; I was interesting to take a look at other possible solutions.



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: j-beda on Feb 15, '11 05:24:14PM

If you need email notification then I don't have any other pointers, but if you just want a domain name to resolve to the correct IP address as that IP address gets changed, then the dnsupdate.org client has done well by me.

I have used the client http://www.dnsupdate.org/ to update a DNS listing at zoneedit.com for my domain over a number of years. zoneedit.com does free dns listing for a few domains before you need to kick them some bucks. Once installed configured to use zoneedit.com the dnsupdate daemon magically gave laptop.example.com the correct 192.168.1.xxx address automatically, with no need for any further work. I found that easier than having to deal with email messages.

I haven't set up anything at dyndns.org for a while (my last email to or from them seems to be dated in 2003), so maybe it has gotten more difficult to make use of their free services without having to say "no thanks" to all of their paid services. Using zoneedit (or other providers?) means you need not deal with dyndns.org at all, but I also haven't opened a new zoneedit account in years (though I continue to use them for some DNS services) - I don't know how onerous their current signup procedure is.

Edited on Feb 15, '11 05:27:28PM by j-beda



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: GlacierRacing on Feb 14, '11 08:57:21AM

He only gets an email when his IP address changes, not every time the script runs. So it's probably not that many emails.

DYNDNS is for internet accessible addresses. He's probably got a non-routable internal IP address, hence the need to use VPN to access from home.

---
Dave



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: Jwink3101 on Feb 14, '11 08:28:12AM

I wonder about the firewalls on this. It seems as though you could still have issues. I guess if you can VPN into the network, then you are fine.

I am also a bit curious about main UNIX application. I have played with it from my laptop and I have found that when I am on my University's campus, their firewall blocks the send. When I am on my home connection, my spam filter blocks it incoming. Have you found a way around that?



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: macsadmn on Feb 14, '11 08:44:13AM

We really haven't had any firewall issues with this; we are mostly sending to a mail server on our local network. I seem to recall that I may have had to mark the messages as "not junk" once in the Mail.app. We have also tested sending to outside email addresses, like hotmail and gmail and have not had any issues with sending to them either - other than the messages showing up in the junk mailbox the first time. If your outbound firewall rules are strict really strict, then I suppose there could be issues with using UNIX mail to send messages.



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: arcticmac on Feb 14, '11 08:45:17AM

A security note here: you want to make sure that the script that you're planning to have automatically executed with root permissions is not world writable - if it is, anyone who can access your machine a little bit can easily do anything they want, since all they have to do is edit your script and then wait 10 minutes for crond to execute it with root permissions. Maybe you don't care for your setup, but since you're posting instructions for other people, it's worth at least mentioning; it doesn't take all that long to do a <code>sudo chown root:wheel scriptname</code>.

Also, are you sure you need to be logged in for it to work with your user's permissions? I can't actually think why that should need to be the case?

Another thing to consider would be doing this via launchd. It can probably be setup to trigger running your script only when the network setup actually changes, which is a nice thing for all the reasons that event-driven code is better than polling.



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: macsadmn on Feb 14, '11 09:08:50AM

arcticmac, good catch on the security of the script. I neglected to mention that; thanks for pointing it out. I'm not entirely sure about the script running as a non-root user when no one is not logged in. I think I tested it, but it's been quite some time since I implement this. It may be worth looking into.

As for the launchd suggestion... that crossed my mind in the exact way you mentioned, but I am not familiar enough with launchd to make it happen. I was secretly hoping that someone might know more about launchd than me and post a way to do that. But, you've now forced the secret, hidden agenda, out of me. ;-)



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: blank on Feb 14, '11 10:25:17AM

Why not just use Teamviewer? App is free for personal use - and you can connect from your ipad to your macbook from everywhere over the internet :)



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: macsadmn on Feb 14, '11 01:30:52PM

We tested TeamViewer and loved it! But, be careful... TeamViewer is not free for educational or corporate use. We had many, many conversations with TeamViewer sales about their pricing options. They did come down in price for educational use, but not to a price that I thought it made it worth our investment. Also, they do track IP connections, so eventually, they may crack down on your use ~ especially if you're connecting through a corporate connection with multiple users using it. I've read reports of some users being banned because of this.

Hope that helps explain part of the reason we developed our own solution.



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: Asmus Vierck on Feb 14, '11 03:44:12PM

Erm.. if it is a local IP, why not use Bonjour?? After all, thats what it was invented for! (i.e. given your Macs name is "John Doe Mac Pro" you will be able to reach it at john-doe-mac-pro.local:5900 or you could ping the .local name to get the IP) And if it iss not a local IP why not use Dyn DNS?



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: macsadmn on Feb 14, '11 06:43:15PM

"...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." (i.e. I'm on the same WAN, so I still get a private IP address, but it's NOT in the same LAN as my laptop). Typically network administrators don't configure a WAN to let Bonjour traffic traverse it.



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: Mac Berry on Feb 15, '11 03:31:51AM

I guess for some reason it's not possible, but can you not simply ask your admin for a fixed internal IP?

Also, why the need for VPN when at home, but not when out and about? Or maybe you do use VPN always, and it's just not mentioned? Thinking about it you must be, otherwise the internal IP would be irrelevant anyway as you'd have to set that up on the router for port forwarding, and would only need the router's external IP for VNC.

Edited on Feb 15, '11 04:36:57AM by Mac Berry



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: macsadmn on Feb 15, '11 06:19:27AM

Actually, I could ask our admin for a fixed IP, but it would only be helpful for when my laptop is in my primary office. There are times when my laptop is at my secondary office. Additionally, there have even been times when I have been working on a project in a building data closet and then gotten called off to go to another building. Instead of packing up the laptop, I can just grab my iPad and still have the ability to remote back to my laptop if needed.

The need for VPN use at home is because we use private IP addresses on our work LAN's - not public IP's. I only use VPN when I'm off of our WAN (a primary purpose of VPN). To help clarify, picture this layout for multiple sites on a WAN: building/LAN #1 has an IP scheme of 10.1.x.x, building/LAN #2 has an IP scheme of 10.2.x.x, ..., building/LAN #10 has 10.10.x.x, etc.. In our case, all sites are connected by fiber or wireless and we are able to route non-broadcast traffic across the WAN. By using VPN on the outside, we get dropped onto a "LAN" that allows us access to our WAN.

I should also add that the part of the hint about tracking external IP address changes is merely a "bonus" for those people that would like to know when their public IP changes. If you are connecting from within the same WAN, or via VPN, you do not need to add that to your script. For the true intent of the hint, It is not at all necessary to include the "bonus" in the IP-Change-Notification.sh script.



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: Mac Berry on Feb 15, '11 07:52:34AM

OK thanks, makes sense.

I have no experience of WAN's! For me, there's a LAN, then the internet, so I'm either on the LAN or I'm not!

OK, so the hint is extremely useful if you find yourself leaving your laptop in differing locations within a WAN, causing your private IP to change, but that's the key point if I'm understanding properly - it's only useful in that situation. If your "server" is either outside your own WAN/LAN (eg at a client's location, or as in my case, my daughter's laptop being in any one of several places at and around uni), knowing the private and public IP's won't help one bit, because you still need a way to access the WAN/LAN it's on remotely, such as VPN or port forwarding.



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: macsadmn on Feb 15, '11 08:34:01AM

You are correct. However, if you're looking to support your daughter remotely, I would definitely check out TeamViewer. It is free for personal use. If you're looking for a free way to remotely support business clients, you might consider Mikogo (http://www.mikogo.com/). It is a bit less user friendly than TeamViewer, but it's completely free. The disadvantage is that there is no iPad support :-( Hopefully the developers will add an iPad app at some point.



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: tom larkin on Feb 15, '11 08:45:58PM

Why not have launchd control this instead of cron?



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: macsadmn on Feb 16, '11 08:30:43AM

You may not have seen my earlier reply:

"As for the launchd suggestion... that crossed my mind in the exact way you mentioned, but I am not familiar enough with launchd to make it happen. I was secretly hoping that someone might know more about launchd than me and post a way to do that. But, you've now forced the secret, hidden agenda, out of me. ;-)"

Honestly, I do think launchd would be the way to go, but I am not familiar enough to make it trigger the script when a network setup event happens. I could use launchd to run the script every X minutes like I do with the cron task, but in that case, there really isn't any advantage to using launchd over cron.

If anyone has a suggestion on how to implement this via launchd when a network setup event happens, I'd be grateful and happy to work with them on it.



[ Reply to This | # ]
Remote Control Your DHCP Connected Laptop from Your iPad
Authored by: tom larkin on Feb 16, '11 11:09:23AM

Take a look at Lingon it will help you learn how to add program arguments, strings, boolean, dictionary items, and all of that into launchd items. However, you are right in some levels launchd in certain application works the same as cron does. I just prefer to always use launchd.



[ Reply to This | # ]
Fix For Lion
Authored by: desepticon on Apr 10, '12 12:04:39AM

I'm running Lion and this wasn't working for me so I fixed some things. I changed the script for external ip addresses to use wget, which isn't default on os x. I added growlnotify notification and fixed a commenting issue at the bottom. Also, you should use launchd instead of cron to schedule it.

#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/opt/local/bin/

# Written to email you if your computer has an IP address change. Invoke with a launchd plist.


# 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='xxxxxxxxx@xxxx.com'

echo "Checking current internal and external ip address..."
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
echo >> /tmp/myip_temp.txt
echo "Outside:" >> /tmp/myip_temp.txt
wget http://automation.whatismyip.com/n09230945.asp -O - >> /tmp/myip_temp.txt

if diff /tmp/myip_temp.txt /tmp/myip.txt &> /dev/null; then exit; else
echo "Your ip adress has changed. Notifying you via email now..."
mv /tmp/myip_temp.txt /tmp/myip.txt
growlnotify --image /Users/user/Pictures/icons/xicon.png -i png -p High -s -t MyXProtect -m "Your ip address has changed."
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

############



[ Reply to This | # ]