首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Mac OS X 10.11中,使用命令行打开VPN连接窗口时会出现错误

在Mac OS X 10.11中,使用命令行打开VPN连接窗口时会出现错误
EN

Stack Overflow用户
提问于 2015-10-06 04:13:42
回答 5查看 6.8K关注 0票数 11

在Mac 10.10上,我可以运行以下命令来打开<=连接窗口:

代码语言:javascript
复制
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
}

这将打开连接窗口(与从VPN下拉列表中选择"LF VPN“网络相同)。然而,在El Capitan中,我得到了以下错误:

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

在El Capitan中如何做与此等效的操作,以及如何进行调试?

EN

回答 5

Stack Overflow用户

发布于 2015-10-07 13:31:36

我使用的是scutil,它在OS X 10.11上运行完美

代码语言:javascript
复制
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
票数 16
EN

Stack Overflow用户

发布于 2016-07-01 20:56:19

代码语言:javascript
复制
VPN="YOUR_VPN_NAME"
IS_CONNECTED=$(test -z `scutil --nc status "$VPN" | grep Connected` && echo 0 || echo 1);

if [ $IS_CONNECTED = 1 ]; then
  scutil --nc stop "$VPN"
else
  scutil --nc start "$VPN"
fi
票数 10
EN

Stack Overflow用户

发布于 2015-10-09 13:01:21

请改用shell脚本:

代码语言:javascript
复制
scutil --nc start "$service"    #connect
scutil --nc stop "$service"     #disconnect
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32957121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档