0

I have been trying to connect to my company vpn using python (basically so that I can then connect to the database for analysis using pyodbc and pandas) with the following code I found on SO:

import os

os.system('nmcli c up <VPN_NAME>')

where VPN_NAME is a string. A "1" gets printed and nothing happens. Same when I use "down" to try and close the network. Is there something I am missing here? Thanks.

KLonge
  • 55
  • 7
  • Does this answer your question? [Running shell command and capturing the output](https://stackoverflow.com/questions/4760215/running-shell-command-and-capturing-the-output) – Countour-Integral Jan 29 '21 at 20:34
  • Not quite. I'm not trying to capture the output. I am just trying to run the command so that it actually connects me to my VPN (which is in the WIFI area on my computer, with the username and password already saved in - hope that makes sense) – KLonge Jan 29 '21 at 20:39
  • @Countour-Integral The link actually helped in the end as it showed me that os.system is just running shell commands. Managed to get a solution. Thanks a bunch. – KLonge Jan 29 '21 at 20:50

1 Answers1

0

Figured out the solution. Thanks @Countour-Integral.

Once I realised that os.system is basically running a shell script, I was able to focus my attention away from python and towards actually finding out how to connect and disconnect from VPN using the shell.

The code I used in the end was:

os.system("rasdial [vpn_name] [username] [password]")

os.system("rasdial [vpn_name] /DISCONNECT")

(don't include [ ])

Gonna have to figure out how to check if I'm already connected to the VPN, but I imagine that can't be too difficult. Thanks for the guidance.

KLonge
  • 55
  • 7