Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

raeserbil

macrumors newbie
Original poster
Jul 3, 2013
24
1
Sweden
I have a appelscript that upon startup mount my fileserver as a disk. The problem is that my router does not support nat-loopback, so for the script to be working both when I'm at home on my lan and when I'm outside I need to check "something" and then connect to either 192.168.0.101 (if I'm at home) or to myserver.myftp.org (if I'm outside). Of course, the best solution would be to get a router that supports nat-loopback so I could use myserver.myftp.org all the time but right now that's not an option.

Anyone that can help me with the problem? I guess I just need an if/else condition but what should I check to determine if I'm on my lan or outside?
 
If the IP subnets are different or the full hostnames are different, you could use either:

you could get your IPv4 address by:

Code:
set myIP to IPv4 address of (get system info)

or hostname by:

Code:
set myHostName to host name of (get system info)
 
I'm not sure what you are referring to as a nat-loopback is, but FWIW, I use this script to determine my IP address. Hope this helps:

........................

715 % cat whatsmypublicip.csh
#!/bin/csh

/bin/curl -s http://checkip.dyndns.org | awk '{print $6}' | awk ' BEGIN { FS = "<" } { print $1 } '

716 %
 
Although you asked how to find your IP address, your connected WiFi SSID might be pretty useful too.

Code:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'

So now you have two tests: you are probably on your home network if
1. Your public facing IP address is the same as your home's public facing IP address (ratsg's post), or
2. Your currently connected WiFi SSID is the name of your home network.
 
Thanks for the help. I solved it by using:

Code:
set myName to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'"

if myName = "mySSID" then
…connect to 192.168.0.101
else
…connect to myserver.myftp.org
end if
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.