windows 用于连接和断开 VPN 连接的批处理文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31990775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
batch file to connect and disconnect from vpn connection
提问by derfect
connect.bat
连接.bat
rasdial myvpn
disconnect.bat
断开连接.bat
rasdial myvpn /DISCONNECT
....I assigned those two files a keyboard shortcut to run them and they work perfectly.
....我为这两个文件分配了一个键盘快捷键来运行它们,它们运行良好。
QUESTION: is it possible to make a single .bat that does the following:
问题:是否可以制作一个执行以下操作的单个 .bat:
if(connected)
disconnect
else
connect
回答by wOxxOm
Based on
ping
in case the VPN server IP is always the same:ping -n 1 1.2.3.4 && rasdial myvpn /disconnect || rasdial myvpn
Replace 1.2.3.4 with your VPN server ip (use
ipconfig /all
when connected) and put this in your batch file or directly in the shortcut properties prepending withcmd /c
in the latter case.Based on connection name:
ipconfig|find/i "myvpn" && rasdial myvpn /disconnect || rasdial myvpn
Replace
myvpn
with your VPN connection name
基于
ping
VPN 服务器 IP 始终相同的情况:ping -n 1 1.2.3.4 && rasdial myvpn /disconnect || rasdial myvpn
将 1.2.3.4 替换为您的 VPN 服务器 ip(
ipconfig /all
连接时使用)并将其放入批处理文件中或直接放入cmd /c
后一种情况下前缀为 的快捷方式属性中。基于连接名称:
ipconfig|find/i "myvpn" && rasdial myvpn /disconnect || rasdial myvpn
替换
myvpn
为您的 VPN 连接名称