choose between already defined VPN connections and automatically logs in!
OS: tested on windows only
Pay attention that this script will focus the VPN dialog and type the password. If the focus is lost, the script can type and sent the password to active windows - so if you run the script -> don't click on other applications, use it with caution
- you need pyautogui installed:
pip install pyautogui
pwd="add-your-password-here"
from time import sleep
import pyautogui
import subprocess
current_connection = subprocess.Popen("rasdial", shell=True, stdout=subprocess.PIPE).stdout.read()
print(current_connection)
# VPN-Name sis the actual VPN name
connections = [
"VPN-Name1",
"VPN-Name2",
"VPN-Name3"
]
index = 1
print("Available VPN Connections:")
for connection in connections:
print("\t{} - {}".format(index, connection))
index+=1
conn_id = raw_input('\t What VPN do you want to setup?: ')
chosen_connection = connections[int(conn_id)-1]
## use this if you alrady have your password set in settings.xml file so we can reuse it ;)
#cmd = "cat ~/.m2/settings.xml | grep 'password' | head -n 1 "
#output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read()
#pwd=output.split(" <password>")[-1].split("</password>")[0]
subprocess.Popen('rasphone -d "{}"'.format(chosen_connection), shell=True, stdout=subprocess.PIPE)
sleep(2)
pyautogui.typewrite('{}\n'.format(pwd))
# rasdial
# rasdial "The VPN" /DISCONNECTor choose another approach to run the vpn-connect.py
# this will use powershell to execute the python script
# you can create a shortcut for this on your desktop
powershell.exe -ExecutionPolicy Bypass -Command "python.exe vpn-connect.py"