1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

determine ip in applescript

Discussion in 'Mac Programming' started by raeserbil, Aug 17, 2013.

  1. macrumors newbie

    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 (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?
  2. macrumors 6502a

  3. macrumors member

    If the IP subnets are different or the full hostnames are different, you could use either:

    you could get your IPv4 address by:

    set myIP to IPv4 address of (get system info)
    or hostname by:

    set myHostName to host name of (get system info)
  4. macrumors 6502

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

    716 %
  5. mwb
    macrumors newbie

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

    /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.
  6. macrumors newbie

    Thanks for the help. I solved it by using:

    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
    …connect to myserver.myftp.org
    end if

Share This Page