首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过AppleScript连接IKEv2虚拟专用网?

如何通过AppleScript连接IKEv2虚拟专用网?
EN

Stack Overflow用户
提问于 2016-08-23 10:53:30
回答 3查看 2.5K关注 0票数 1

有没有人在使用IKEv2网络服务时体验过AppleScript?

在El Capitan中,我可以创建IKEv2虚拟专用网连接并正确连接。但是,AppleScript不能与这种连接/服务一起工作,它不能获得具有名称的服务,它不能列出来自该服务的连接。

代码语言:javascript
复制
tell application "System Events"
   tell current location of network preferences
      set service_name to "IKEv2_connection_name"
      do shell script (do shell script "scutil --nc start \"" & service_name & "\"")
   end tell
end tell

下面是错误:

代码语言:javascript
复制
error "System Events got an error: No service" number 1

AppleScript似乎无法识别IKEv2 VPN连接。因此,我尝试运行另一个脚本来打印系统中所有当前的互联网连接:

代码语言:javascript
复制
tell application "System Events"
   tell current location of network preferences
      set names to get name of every service
   end tell
end tell

结果显示了所有的网络连接(包括"Wi-Fi","USB Ethernet","Bluetooth PAN","Thunderbolt Bridge",所有L2TP,PTPP,IPSec类型的虚拟专用网连接),但它没有列出任何IKEv2连接,尽管我已经设置了其中的一些,它们都在工作。

EN

回答 3

Stack Overflow用户

发布于 2017-07-28 14:55:09

我能够使用UI脚本让它工作。到目前为止,这个脚本似乎工作得很好,我想我已经尽可能地让它变得用户友好。它要求系统首选项始终处于打开状态,但可以隐藏窗口。如果脚本启动时关闭了系统首选项,则脚本将启动,然后自动隐藏系统首选项。主要的不便之处在于,当脚本运行时,系统首选项实际上被锁定在网络窗格中。请随时尝试,如果您有任何问题或建议,请让我知道!您需要将"MY VPN SERVICE NAME“替换为您希望保持连接的VPN服务的名称。您可能还想修改底部的延迟。

代码语言:javascript
复制
repeat while true
tell application "System Events"
    tell application process "System Preferences"
        if not (window 1 exists) then
            tell application "System Preferences"
                activate
            end tell
            repeat while not (menu bar 1 exists)
            end repeat
            repeat while not (menu "System Preferences" of menu bar 1 exists)
            end repeat
            repeat while not (menu item "Hide System Preferences" of menu "System Preferences" of menu bar 1 exists)
            end repeat
            delay 3
            click menu item "Hide System Preferences" of menu "System Preferences" of menu bar 1
        end if

        click menu item "Network" of menu "View" of menu bar 1

        tell window 1
            repeat while not (rows of table 1 of scroll area 1 exists)
            end repeat
            repeat with current_row in (rows of table 1 of scroll area 1)
                if value of static text 1 of current_row contains "MY VPN SERVICE NAME" then
                    select current_row
                    exit repeat
                end if
            end repeat

            repeat with current_button in (buttons in group 1)
                if name of current_button is equal to "Connect" then
                    click current_button
                    exit repeat
                end if
            end repeat
        end tell
    end tell
end tell
delay 60
end repeat
票数 2
EN

Stack Overflow用户

发布于 2019-03-09 20:54:59

这不是对你问题的直接回答,而是实现同样目标的另一种方式;

这家伙创建了一个应用程序(源代码也可用)来做scutil和AppleScript做不到的事情:https://blog.timac.org/2018/0719-vpnstatus/

票数 1
EN

Stack Overflow用户

发布于 2016-09-01 19:28:43

有一些关于这一点的报道,这似乎是在OSX10.10中对AppleScript所做的一些更改,它停止了connection对象中的服务以列出IKEv2 VPN。

你走在正确的道路上,只是不要使用location:

代码语言:javascript
复制
tell application "System Events"
      set service_name to "IKEv2_connection_name"
      do shell script "scutil --nc start \"" & service_name & "\""
end tell

根据这个答案,你还可以看到更多的scutil选项:

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39091587

复制
相关文章

相似问题

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