1

是否可以在我的可可应用程序或命令行中设置 vpn 连接?如果我想做这样的事情,我应该从哪里开始?

4

2 回答 2

0

我在这里找到了一种使用 AppleScript 运行配置 VPN 的方法:

https://superuser.com/questions/358513/start-configured-vpn-from-command-line-osx

那是我的代码修改:

tell application "System Events"
tell current location of network preferences
    try
        set VPN to service "MyVPN" -- your VPN name here
    on error
    return "NOT A CORRECT VPN FOUND ON THIS COMPUTER"
    end try
    if exists VPN then
        connect VPN
    end if

    delay 15

    if current configuration of VPN is connected then
        return "OK"
    else
        return "CONNECTION ERROR"
    end if
end tell

如果您愿意,您可以以这种方式在您的 COCOA 项目中运行该脚本: Getting AppleScript return value in Obj-C

    NSString* path = [[NSBundle mainBundle] pathForResource:@"VPNCONNECTION" ofType:@"scpt"];
    NSURL* url = [NSURL fileURLWithPath:path];
    NSDictionary* errors = [NSDictionary dictionary];
    NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
    NSAppleEventDescriptor *result = [appleScript executeAndReturnError:&errors];

    NSLog(@"result = %@",result);

你可以在这里找到我的问题: Objective-C start a VPN Connection

于 2013-09-26T07:27:54.827 回答
0

大多数时候 Cocoa 应用程序只是充当命令行 OpenVPN 的前端:http ://www.openvpn.net/

于 2009-08-27T15:20:06.447 回答