在 OSX 中自动执行 VPN 连接等任务?

在 OSX 中自动执行 VPN 连接等任务?

我正在使用学校的 VPN 服务浏览 Netflix。我大部分时间都必须连接到 VPN。我的学校使用 Cisco AnyConnect Secure Mobility Client。每次连接时我都必须输入密码并接受横幅。有没有办法在 OS X 上自动完成此连接?

答案1

如果您使用 OS X 来控制您的连接: 在此处输入图片描述

出现这种情况的原因是您正在连接的 Cisco 盒子强制交互。这实际上是 Cisco VPN 聚合器上的一项强制安全性设置。根据 Cisco 与 Apple 达成的协议(Cisco 和 Apple 均表示),Apple 不提供规避(Apple Script/Automator)的功能。我之前调查过这个问题,这是双方给我的答案。

Cisco OS X VPN 客户端也是如此。

答案2

是的,您可以使用 AppleScript 自动执行此操作。

这是我使用的脚本:

-- 1. Place in ~/Library/Scripts and enable the Applescript menu via the Applescript Editor
--    (Or export to .app to run from spotlight.)
-- 2. Substitute "vpn.example.com", "username" and "redacted" for your VPN server and password
-- 3. Open Security & Privacy System Preferences, go to Privacy, Accessibility
-- 4. Enable Applescript Editor and System UI Server (or for this .app if so exported)
-- 5. Trigger script from the menu (or run from spotlight)
-- 6. Enjoy being connected
-- 7. Run script again to close connection


-- AnyConnect now refered to as targetApp
set targetApp to "Cisco AnyConnect Secure Mobility Client"


-- Determine if AnyConnect is currently running
tell application "System Events"
    set processExists to exists process targetApp
end tell


-- Close connection if running; else start connection and fill in password
if processExists is true then
    tell application targetApp
        quit
    end tell
else
    tell application targetApp
        activate
    end tell

    tell application "System Events"
        repeat until (window 1 of process targetApp exists)
            delay 1
        end repeat
        tell process targetApp
            keystroke ("vpn.example.com" as string)
            keystroke return
        end tell
        repeat until (window 2 of process targetApp exists)
            delay 1
        end repeat
        tell process targetApp
            keystroke (tab) using {shift down}
            keystroke ("username" as string)
            keystroke tab
            keystroke ("redacted" as string)
            keystroke return
        end tell
        delay 1
        tell process targetApp
            keystroke return
        end tell

    end tell
end if

这是我找到并修改的脚本;我不确定原作者是谁,因为有多个版本流传。我从https://gist.github.com/twksos/44b45abf5263635776ec

相关内容