Reputation: 321
Currently, you have to manually connect to a remote database to extract info via an openvpn
connection openvpn-gui.exe
to extract the info and disconnect after each extraction job.
Connection is authenticated by a config.ovpn
file stored locally.
Is there a way to automate the (connect > extract data > disconnect) process?
Upvotes: 3
Views: 17810
Reputation: 321
Managed to solve this issue...
Log in to your openvpn server domain via browser (e.g. https://12.345.678.999/)
Download Connection Profile "Yourself (autologin profile)". File usually named "client.ovpn"
Paste "client.ovpn" file in "C:\Program Files\OpenVPN\config"
From openvpn-gui.exe desktop icon, import file and direct it to "client.ovpn"
ovpn_connect.bat
"C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --command connect client.ovpn
ovpn_disconnect.bat
"C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --command disconnect client.ovpn
Follow website instruction to allow .bat file to be run with admin rights.
Insert code into python script and run as per usual
import subprocess, time
# Connect to OpenVPN
subprocess.call([r'filepath\ovpn_connect.bat'])
time.sleep(15) # adjust your connection time
print("Connect OpenVPN")
# Disconnect from OpenVPN
subprocess.call([r'filepath\ovpn_disconnect.bat'])
print("Disconnect OpenVPN")
Upvotes: 4