Feeds:
Posts
Comments

Posts Tagged ‘ip’

A good script.

A good script.

I just finished setting up something neat for my MacBook Pro: a script that takes the IP address of the laptop on wake and writes it to a file that is then synced online via Dropbox.

It starts with the set of terminal commands on scripts called SleepWatcher. This program looks for a file called .sleep and .wakeup int he users home directory and executes them upon sleep and wake respectively. They can contain any UNIX script from say “Goodnight Michael” to, well, grabbing the current IP.

The command used to get the current IP and write it to a file is:

curl http://myip.ozymo.com -o /Users/michaelhutchins/Documents/Dropbox/wan_ip_mac.txt

With the /michaelhutchins… part replaced with your username and where you want the file to go (and be called). To make the use TextEdit or anything to make a file called sleep.txt. Then rename this to .sleep saying yes to all the warning of hidden files and removing the .txt extension. My full script is the above with one added line:

sleep 5;

curl http://myip.ozymo.com -o /Users/michaelhutchins/Documents/Dropbox/wan_ip_mac.txt;

The sleep 5 just waits five seconds so the computer can make the connection to the internet. Once it was done in Terminal I typed chmod +x .wakeup to make it executable. With this and sleepwatcher installed it now updated the IP address whenever it wakes up.

Why is this useful? I see it as a security measure. If my laptop is ever lost or stolen I can use the IP to SSH in to maybe find out where it went or at least narrow down the options. I can also use Screen Sharing through OS X to see what is on the screen by connecting with the IP address. Or if the IP is for a coffee house or public place a well placed “say “I am stolen!” on repeat may help.

Also in the future I may see about setting my computer up as a file server I can wake remotely in case I need to get a file. Though I have yet to experiment with that.

Advertisements

Read Full Post »