I'm trying to create a script that will bring up a vpn connection. I modeled my script from this question and it works fine for my purposes but I find that as soon as I close the script the vpn connection is interrupted. When using the "-b" option I get the following at the end of my child.read():
Established DTLS connection (using GnuTLS). Ciphersuite (DTLS0.9)-(RSA)-(AES-256-CBC)-(SHA1).\r\nSSL operation canceled\r\nUser detached from session (SIGHUP); exiting.\r\n'
Here is my code:
import os, sys, subprocess, time, re, pexpect
import signal
def signal_handler(sig, frame):
print("sigHUUUUUP")
sys.exit
child = pexpect.spawn('sudo openconnect -b --script /etc/vpnc/vpnc-script remote.host')
child.expect('.*')
child.sendline('yes')
child.expect('.*')
child.sendline('ipsec')
child.expect('.*')
child.sendline('username')
child.expect('.*')
child.sendline('password')
signal.signal(signal.SIGHUP, signal_handler)
time.sleep(15)
I have a strong preference to remain in python but I'm open to other ways of running openconnect and feeding it the expected passwords. Mainly looking for a way to have the vpn setup without needing to run the script continuously.
I've tried using ignore_sighup=True and that doesn't work.