Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Mac OS X 10.11, Opening a VPN connection window with the command line gives me an error

On Mac OS X <= 10.10, I could run the following command to open a VPN connection window:

function go-vpn {
/usr/bin/env osascript <<-EOF
tell application "System Events"
        tell current location of network preferences
                set VPN to service "LF VPN"
                if exists VPN then connect VPN
                repeat while (current configuration of VPN is not connected)
                    delay 1
                end repeat
        end tell
end tell
EOF
}

This would open the connection window (same as selecting the "LF VPN" network from the VPN dropdown). In El Capitan, however, I get the following error:

execution error: System Events got an error: Can’t get current configuration of service id "18E8C59B-C186-4669-9F8F-FA67D7AA6E53" of network preferences. (-1728)

How would one do the equivalent of this in El Capitan, and how can this be debugged?

Annotated screen shot

like image 709
alberto56 Avatar asked Oct 05 '15 20:10

alberto56


People also ask

Why won't my Mac connect to a VPN?

Try to reinstall the app's profile, it should fix the issue; From System Preferences > Network> select Hotspot Shield VPN profile. Click on the minus "-" sign at the bottom to remove the profile. Click Apply to save changes.

Can connect to VPN but Cannot Access Network Mac?

Check your Firewall settings so that it doesn't interfere with your VPN traffic or blocks VPN data packets. Switch to a newer or lighter VPN protocol as described above. On rare occasions, a VPN may act up when you tap in WiFi, so try accessing the internet via cable.

Where are VPN settings stored on Mac?

When using the Default profile with Configuration: for the VPN and modifying its settings, the /Library/Preferences/com. apple. networkextension. plist file, the one starting in the root of the e.g. Macintosh HD, not your Home folder, will contain the VPN settings.


1 Answers

I'm using scutil instead, and it works flawlessly on OS X 10.11

set vpn_name to "'VPN Connection Name'"
set user_name to "my_user_name"
set otp_token to "XYZXYZABCABC"

tell application "System Events"
    set rc to do shell script "scutil --nc status " & vpn_name
    if rc starts with "Connected" then
        do shell script "scutil --nc stop " & vpn_name
    else
        set PWScript to "security find-generic-password -D \"802.1X Password\" -w -a " & user_name
        set passwd to do shell script PWScript
        -- installed through "brew install oath-toolkit"
        set OTPScript to "/usr/local/bin/oathtool --totp --base32 " & otp_token
        set otp to do shell script OTPScript
        do shell script "scutil --nc start " & vpn_name & " --user " & user_name
        delay 2
        keystroke passwd
        keystroke otp
        keystroke return
    end if
end tell
like image 65
captnswing Avatar answered Sep 27 '22 22:09

captnswing