Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   AppleScript to check IP of local Machine then Backup (http://www.mac-forums.com/forums/os-x-development-darwin/145179-applescript-check-ip-local-machine-then-backup.html)

AshUk 03-14-2009 03:55 PM

AppleScript to check IP of local Machine then Backup
 
Hi,

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.

Ash.

xstep 03-15-2009 04: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 10: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 11: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 01:17 PM

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

"fe80::21b:63ff:feb8:e207%en0
13.201.180.161"

AshUk 03-16-2009 01:21 PM

Found it:

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


All times are GMT -4. The time now is 06:55 PM.

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