简体   繁体   English

如何使用命令行在 windows 上使用 openvpn?

[英]How can one use the command-line to use openvpn on windows?

I have been trying to come up with a way to interact with openvpn on windows.我一直在尝试想出一种与 windows 上的 openvpn 交互的方法。 I did fine the openvpn.exe but there are no commands that will use a config file to connect with a vpn server.我对 openvpn.exe 做得很好,但是没有命令可以使用配置文件连接到 vpn 服务器。 I am using nordvpn by the way.顺便说一句,我正在使用nordvpn。 Specifically a tcp Canadian server.特别是 tcp 加拿大服务器。 I did find some people suggesting to use the openvpn-gui.exe to run the program but it defeats the purpose.我确实发现有人建议使用 openvpn-gui.exe 来运行该程序,但这违背了目的。 I want t to completely be on command line.我希望 t 完全在命令行上。 Secondly, i need the command line to work as i want to integrate openvopn into a script which will download stuff from the internet.其次,我需要命令行才能工作,因为我想将 openvopn 集成到一个脚本中,该脚本将从互联网上下载东西。 Anyone with any idea how to do it?有人知道怎么做吗?

For anyone looking into this in 2021, please find below a connect and a disconnect.对于 2021 年调查此问题的任何人,请在下方找到连接和断开连接。

To connect连接

"C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --command connect yourconfigfile.ovpn

To disconnect断开连接

"C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --command disconnect yourconfigfile.ovpn

For windows users... Both of these can be placed in a.bat file and automated with task scheduler, works like a charm.对于 windows 用户......这两者都可以放在一个 .bat 文件中并使用任务调度程序自动执行,就像一个魅力。

Another CMD example:另一个 CMD 示例:

"C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --connect config.ovpn

Replace 'config.ovpn' by your configuration file.用您的配置文件替换“config.ovpn”。 You also may have another path to openvpn-gui.exe .您也可能有其他途径openvpn-gui.exe

It will work if you have no openVPN correctly installed so you can't run openvpn-gui... from cmd.如果您没有正确安装 openVPN,它将工作,因此您无法从 cmd 运行openvpn-gui...

So I figured out the answer to the problem.所以我想出了问题的答案。 To control openvpn from command-line on windows:要从 windows 上的命令行控制 openvpn:

  1. Set the Environment Variable so you can access the openvpn-gui.exe from command-line.设置环境变量,以便您可以从命令行访问 openvpn-gui.exe。
  2. Type this command: openvpn-gui --connect [config file] .键入此命令: openvpn-gui --connect [config file] (You are going to need the config file so download it from your vpn provider) (您将需要配置文件,因此请从您的 vpn 提供商处下载)

If you don't want to type the password every time you run the script, edit the config file to read the username and password from a.txt file.如果您不想在每次运行脚本时都输入密码,请编辑配置文件以从 .txt 文件中读取用户名和密码。 Here's a link that can help you do that: https://help.vpntunnel.com/support/solutions/articles/5000613671-how-do-i-save-my-username-password-in-openvpn-for-automatic-login-这是一个可以帮助您做到这一点的链接: https://help.vpntunnel.com/support/solutions/articles/5000613671-how-do-i-save-my-username-password-in-openvpn-for-automatic-登录-

You can actually use the config file with openvpn.exe , but you must provide the full path to it unlike with openvpn-gui.exe :您实际上可以将配置文件与openvpn.exe一起使用,但与openvpn-gui.exe不同,您必须提供完整路径:

openvpn.exe --config "path/to/config.ovpn"

Instructions指示

Step 1. Go to the correct location for x64 systems:步骤 1. Go 到 x64 系统的正确位置:

cd "%ProgramFiles%\OpenVPN Connect" Note: if you have the 32 bits program installed on a 64 bits OS, replace %ProgramFiles% with %ProgramFiles(x86)%. cd "%ProgramFiles%\OpenVPN Connect" 注意:如果您在 64 位操作系统上安装了 32 位程序,请将 %ProgramFiles% 替换为 %ProgramFiles(x86)%。

Step 2. Install the system service:步骤 2.安装系统服务:

ovpnconnector.exe install ovpnconnector.exe 安装

Step 3. Specify connection profile to use (optional):步骤 3.指定要使用的连接配置文件(可选):

ovpnconnector.exe set-config profile <FULL_PATH_AND_FILENAME_TO_PROFILE.OVPN> Note: if your OpenVPN Connect installation file was downloaded from Access Server or OpenVPN Cloud and came with a bundled autologin connection profile, then you can skip step 3. It will then simply default to the bundled connection profile. ovpnconnector.exe set-config profile <FULL_PATH_AND_FILENAME_TO_PROFILE.OVPN> 注意:如果您的 OpenVPN Connect 安装文件是从 Access Server 或 OpenVPN Cloud 下载的并且附带捆绑的自动登录连接配置文件,那么您可以跳过第 3 步。然后它将默认为捆绑的连接配置文件。 It can be found in the program location with the name "ovpnconnector.ovpn" - that is the bundled connection profile.它可以在名为“ovpnconnector.ovpn”的程序位置中找到——即捆绑的连接配置文件。

Step 4. Specify the path to a log file (optional):步骤 4.指定日志文件的路径(可选):

ovpnconnector.exe set-config log <FULL_PATH_AND_FILENAME_TO_LOGFILE.LOG> Note: if you skip step 4, the service will write to the default log file in the program location with the name “ovpnconnector.log”. ovpnconnector.exe set-config log <FULL_PATH_AND_FILENAME_TO_LOGFILE.LOG> 注意:如果您跳过第 4 步,该服务将写入程序位置中名为“ovpnconnector.log”的默认日志文件。

Step 5. Start the service:步骤 5.启动服务:

ovpnconnector.exe start The service will now start the VPN connection and log output to the log file. ovpnconnector.exe start 该服务现在将启动 VPN 连接并将 output 记录到日志文件中。

Note: you will not receive feedback after starting the service if the connection succeeded or not.注意:无论连接成功与否,启动服务后都不会收到反馈。 You can check the log file or use the ping command to verify that the connection is now up and running.您可以检查日志文件或使用 ping 命令来验证连接现在是否已启动并正在运行。

Important: OpenVPN Connect client should not be running, otherwise service startup will abort.重要提示: OpenVPN Connect 客户端不应运行,否则服务启动将中止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以使用doxygen来记录命令行程序吗? - Can I use doxygen to document a command-line program? 如何使用子进程库在顶级python文件中使用命令行参数调用其他python文件? - How can I use the subprocess library to call other python files with command-line arguments in a top-level python file? 如何使用optparse将命令行参数拆分为选项和位置参数? - How do I use optparse to just split the command-line arguments into options and positional args? Windows 7中使用PyPI进行命令行注册的问题 - Problem with command-line registeration with PyPI in Windows 7 如何使用 vanila python 在命令行上获取 arguments? - How can I get the arguments on a command-line with vanila python? 如何使用 argparse 将列表作为命令行参数传递? - How can I pass a list as a command-line argument with argparse? python中的一个命令行可自动执行代码 - One command-line in python to automatize code 如何在Windows命令行上使用pg_restore? - How to use pg_restore on Windows Command Line? 如何在Windows 10命令提示符中运行中心线命令行工具 - How to run centerline command-line tool in windows 10 command promt 如何在 Windows 命令行中使用 python 'input' function ? - How to use python 'input' function in Windows command line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM