以编程方式确定 Cisco VPN 客户端是否已连接
我正在使用基本的 Cisco VPN 客户端(我相信是 v.5)。 无论如何,是否可以以编程方式确定特定配置文件(或与此相关的任何配置文件)是否已连接?
我希望以某种方式从客户本身获得状态。 我不想尝试 ping VPN 另一端的某个 IP 才能查看是否得到响应。
I am working with the basic Cisco VPN client (v.5 I believe). Is there anyway to determine programatically if a partciular profile (or any profile for that matter) is connected?
I'm looking to somehow get a status from the client itself. I don't want to have to try to ping some IP on the other end of the VPN to see if I get a response.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
有一个用于 思科 VPN (vpnapi.dll)。
There is an API for Cisco VPN (vpnapi.dll).
我不知道 Cisco VPN 客户端有任何 API,但您可以使用底层操作系统。
在 Mac OS X 上,您可以查询系统配置框架,因为当 Cisco VPN 客户端连接时,它会在配置目录(DNS 等)中创建许多密钥:
可以在纯 C Carbon 或 ObjC Cocoa 中实现与上述内容等效的编程。
I am unaware of any APIs for Cisco VPN client but you could use the underlying OS.
On Mac OS X, you can query the System Configuration framework because when Cisco VPN client connects it creates a number of keys in the configuration directory (DNS and stuff):
The programmatic equivalent of the above can be achieved in plain C Carbon or ObjC Cocoa.
实际上,有几种方法可以不使用 API(我仍然找不到/DL),
最简单的方法之一是检查注册表设置:
HKEY_LOCAL_MACHINE\SOFTWARE\Cisco Systems\VPN Client\AllAccess\TunnelEstablished(0 或 1)
另一种方法是通过使用 ManagementObjectSearcher 建立的网络接口的名称来检测它,示例代码如下:
另一种方法是使用 process.start 运行“vpnclient stat”的 CLI(命令行),将标准输出重定向到应用程序中的字符串生成器,然后检查字符串是否包含适当的数据 - 有关详细信息,请参阅此处:
http://www.cisco.com/en /US/docs/security/vpn_client/cisco_vpn_client/vpn_client46/administration/guide/vcAch5.html
There are several ways, actually, without using the API (which I still cant find/DL)
One of the easiest ways is to check a registry setting found at:
HKEY_LOCAL_MACHINE\SOFTWARE\Cisco Systems\VPN Client\AllAccess\TunnelEstablished (0 or 1)
Another way is to do it is to detect it by the name of the network interface it establishes via using ManagementObjectSearcher, sample code below:
Yet another way is to use process.start to run a CLI (command line) of "vpnclient stat", redirect standard output to a stringbuilder in your app and then check the string whether it contains appropriate data - for more info on this see here:
http://www.cisco.com/en/US/docs/security/vpn_client/cisco_vpn_client/vpn_client46/administration/guide/vcAch5.html
下面是一个检查连接状态的vbs脚本:
Below a vbs script to check the connection status:
好吧,如果一切都失败了,请解析“route”的输出。 CiscoVPN 使用的路由在那里有一个明显的标记。
Well if all else fails, parse the output of "route". The routing used by CiscoVPN has a telltale mark there.
正如“diciu”所写,您可以查询系统配置框架。 他给出的 scutil 命令的编程等效项类似于
使用上面的命令,您可以判断 Cisco VPN 客户端是否已连接。 然后,您可以执行类似的操作来获取与 VPN 连接关联的 DNS 服务器。 我将生成的 DNS 服务器与我公司的 DNS 服务器进行比较,以确定我是否通过 VPN 连接到我的公司。 笨拙,但它有效且速度快 - 无需等待 ping 超时。
请注意,在最新版本的 Cisco VPN 客户端中,思科发布了 API。 不幸的是,它仅适用于 Microsoft Windows。 也许有一天他们会为 Mac 生产一款。
As "diciu" wrote, you can query the System Configuration framework. The programmatic equivalent of the scutil command that he gave is something like
Using the above, you can tell if the Cisco VPN client is connected. You can then do something similar to get the DNS servers associated with the VPN connection. I compare the resulting DNS servers to the DNS server of my company to tell if I'm VPN'd into my company. Klunky, but it works and it's fast - no waiting for a ping to timeout.
Note that with the recent version of the Cisco VPN Client, Cisco published an API. Unfortunately, it's only for Microsoft Windows. Maybe they'll produce one for Macs some day.
根据 @Joshua 的回答,如果您打开或关闭 VPN,这都会回显。
关闭 VPN 时:
打开 VPN 时:
Building on @Joshua's answer, this will echo if you're on or off VPN.
While off VPN:
When on VPN: