macosbashvpn

How to get the currently connected VPN’s name under OS X


I know I can get the Wifi SSID by doing

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | sed -e "s/^  *SSID: //p" -e d

but is there a way to get the VPN name that is currently being used?


Solution

  • Assuming you mean a VPN service registered with Network Preferences, AppleScript, specifically System EventsNetwork Preferences Suite will work:

    tell application "System Events"
        tell current location of network preferences
            get name of every service whose (kind is greater than 11 and kind is less than 16) and connected of current configuration is true
        end tell
    end tell
    

    If you need to access this from the shell, osascript -e is your friend (one -e option per line of AppleScript, mind the quoting and escaping – see man osascript).