-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvpn-connect.py
More file actions
88 lines (71 loc) · 2.93 KB
/
vpn-connect.py
File metadata and controls
88 lines (71 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import subprocess
import os.path
# ------------------------------------------------
# BEGIN - User define variables.
# ------------------------------------------------
## Set browser to chrome or firefox depending on which you use:
#browser = "firefox"
browser = "chrome"
## Firefox profile location:
## Common locations:
## - snap installed: ~/snap/firefox/common/.mozilla/firefox/oc-vpn
## - apt installed: ~/.mozilla/firefox/oc-vpn
FProfile = "~/.mozilla/firefox/oc-vpn"
## Uncomment whichever host you prefer to use:
# vttraffic is the recommended, so that is the preselected option.
host = ""
#host = "vpn.nis.vt.edu/alltraffic"
## Replace PID in the quotes below with your VT PID
## (minus the @vt.edu):
user = ""
# ------------------------------------------------
# END - User define variables.
# ------------------------------------------------
if browser == 'chrome':
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
# Declare webdriver to control browser:
driver = webdriver.Chrome()
elif browser == 'firefox':
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager
# import Geckodriver into your program
import geckodriver_autoinstaller
# Get the latest version every day on 1st excution of your program
geckodriver_autoinstaller.install()
# Declare webdriver to control browser:
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument("-profile")
firefox_profile = os.path.expanduser(FProfile)
options.add_argument(firefox_profile)
driver=webdriver.Firefox(options=options)
else:
print("ERROR: Check your user defined browser setting.")
quit()
# Configure wait, 60 seconds should be more than enough to
# enter all the credentials
wait = WebDriverWait(driver, 60)
# open up the VPN web page
driver.get("https://"+host)
# Keep checking for cookie to appear in the web browser (after
# user is done with authentication process)
dsid = wait.until(lambda driver: driver.get_cookie("DSID"))
# We don't need browser once we have the cookie
driver.quit()
print('\n---------------------------------------------------------------------------')
print('This terminal window needs to stay open for the VPN connection to function.')
print('To close the VPN connection use the keystroke CTRL-C when done.')
print('---------------------------------------------------------------------------\n')
# Run a shell command to start openconnect
subprocess.run(["sudo", "openconnect", "-C", dsid["value"], "--protocol=nc", "-u", user, host])
# Protocols:
# Cisco AnyConnect: anyconnect
# Juniper: nc
# Pulse/Ivanti: pulse (Most Pulse VPNs also support the older Juniper protocol, unless explicitly disabled))
# Palo Alto: gp
# F5: f5, PPP-based
# Fortinet Fortigate: fortinet, PPP-based
# Array: array