Mac Forums

Mac Forums (
-   OS X - Development and Darwin (
-   -   AppleScript to check IP of local Machine then Backup (

AshUk 03-14-2009 02:55 PM

AppleScript to check IP of local Machine then Backup

My MBP is on multiple networks everyday for work and i'd like a script that checks the IP address of my MBP (wireless & wired) and if in a certain subnet, initiate a backup. I have an applescript that mounts my NAS however it would be good to have something that first checks the network i'm on, if home then mount my NAS and run a backup.

Thanks in advance for your help.


xstep 03-15-2009 03:55 PM

Let me google that for you. This was the first hit.

You may want to choose en1 instead of en0 if you are using wireless. Or test for both.

AshUk 03-16-2009 09:19 AM

I can do a "ifconfig en0" to get the details of the interface, i'm curious how i can store and present the 'inet' value, which is the IP Address, as a variable which i can then use later in another script?

Talcon 03-16-2009 10:24 AM

Use the "set" command, for example:

set ipaddress to do shell script "ifconfig en1 | grep 'inet' | awk '{print $2}'"

Once you have this done, you can use it in same script.

AshUk 03-16-2009 12:17 PM

Thanks Talcon, is there a way to specifically only print the IP address, i received this when ran:


AshUk 03-16-2009 12:21 PM

Found it:

ifconfig en0|grep "inet "|cut -d ' ' -f 2

All times are GMT -4. The time now is 11:45 PM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.