【问题标题】:VPN in cocoa app可可应用程序中的 VPN
【发布时间】:2010-11-23 07:44:05
【问题描述】:

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

【问题讨论】:

    标签: objective-c cocoa command-line vpn


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我在这里找到了一种使用 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

      【讨论】:

        猜你喜欢
        • 2015-12-08
        • 1970-01-01
        • 2011-05-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-04
        • 2012-10-13
        相关资源
        最近更新 更多