Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import pexpect
- import sys
- import shutil
- import commands
- username = 'eficode3'
- password = '9bsAUECT'
- add_net_template = 'route add -net 10.3.0.0 netmask 255.255.0.0 gw %s %s'
- add_host_template = 'route add -host %s eth0'
- pekkaniska_vpn_conf_file = '/etc/resolv.conf.pekkaniska'
- resolv_conf_file = '/etc/resolv.conf'
- child = pexpect.spawn('openconnect -b 62.236.217.122')
- child.logfile = sys.stdout
- child.expect(r'Username:')
- child.sendline(username)
- child.expect(r'Password:')
- child.sendline(password)
- child.expect(r'Connected (\w+) as (\d+\.\d+\.\d+\.\d+), using SSL')
- ip_address = child.match.group(2)
- tunnel_name = child.match.group(1)
- print "Detected IP address for tunnel", tunnel_name, "with IP address", ip_address
- child.interact()
- print "Copying file", pekkaniska_vpn_conf_file, "to", resolv_conf_file
- shutil.copyfile(pekkaniska_vpn_conf_file, resolv_conf_file)
- add_net_command = add_net_template % (ip_address, tunnel_name)
- print "calling:", add_net_command
- add_net_output = commands.getoutput(add_net_command)
- print "output:", add_net_output
- add_host_command = add_host_template % (ip_address)
- print "calling:", add_host_command
- add_host_output = commands.getoutput(add_host_command)
- print "output:", add_host_output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement