登录/启动后如何自动连接到VPN?


35

到目前为止,我一直在使用Lion的内置VPN工具。

我想在连接到Internet时自动连接我的VPN。

每当我使用内置工具连接到Internet时,是否可以自动连接我的VPN?

如果无法使用内置工具进行自动连接,您可以为我提供免费的替代产品吗?


在“网络设置”的“高级”下是否没有此选项?我没有Mac。
马特

有没有办法使用Open VPN客户端Viscocity做到这一点?

@christian好问题!我不知道。我已通过Twitter请求他们的支持,但尚未收到答案。但是您可以尝试在他们的论坛中找到解决方案。到目前为止,我一直在使用令人惊叹的Shimo VPN客户端,该客户端支持OpenVPN并内置了此功能。但是,这不能回答您的问题:)。
gentmatt 2012年

@christian Viscosity的最新版本对此进行了设置。当您选择一个VPN配置文件并对其进行编辑时,底部有一个选项,可在Viscosity启动时启动此VPN服务。
gentmatt 2012年

Answers:


42

Apple Script提供了一个很好的解决方案:

on idle
    tell application "System Events"
        tell current location of network preferences
            set myConnection to the service "VPN University"
            if myConnection is not null then
                if current configuration of myConnection is not connected then
                    connect myConnection
                end if
            end if
        end tell
        return 120
    end tell
end idle

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明


2
大!像魅力一样工作。我正在使用Lion 10.7.2。
gentmatt 2011年

1
10.12.3

通过Lifehacker的发现:lifehacker.com/...
约翰·亨特

5

解决此问题的另一种方法是创建一个配置文件(使用Apple Configurator)。使用此工具,重新创建您的VPN配置并保存文件。创建文件后,在文本编辑器中将其打开,然后查找以下内容:

<key>VPNType</key>
<value>(...)</key>

在下面添加以下内容:

<key>OnDemandEnabled</key>
<integer>1</integer>
<key>OnDemandRules</key>
<array>
    <dict>
        <key>Action</key>
        <string>Connect</string>
        <key>InterfaceTypeMatch</key>
        <string>WiFi</string>
    </dict>
    <dict>
        <key>Action</key>
        <string>Connect</string>
        <key>InterfaceTypeMatch</key>
        <string>Cellular</string>
    </dict>
</array>

现在,在安装此配置文件之后,应该在“网络”系统首选项中显示一个复选框“按需连接”。现在,macOS将使您的连接保持活动状态。奖励功能:您还可以根据连接的Wifi网络添加有关VPN何时连接或断开连接的特定规则。

有关所有按需规则,请参阅Apple开发人员站点上的“ 配置文件参考 ”。并请参见strongSwan Wiki,其中显示了一些示例。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.