Advertisement
Guest User

Untitled

a guest
May 25th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. #!/usr/bin/python
  2. import pexpect
  3. import sys
  4. import shutil
  5. import commands
  6.  
  7. username = 'eficode3'
  8. password = '9bsAUECT'
  9.  
  10. add_net_template = 'route add -net 10.3.0.0 netmask 255.255.0.0 gw %s %s'
  11. add_host_template = 'route add -host %s eth0'
  12.  
  13. pekkaniska_vpn_conf_file = '/etc/resolv.conf.pekkaniska'
  14. resolv_conf_file =  '/etc/resolv.conf'
  15.  
  16. child = pexpect.spawn('openconnect -b 62.236.217.122')
  17. child.logfile = sys.stdout
  18. child.expect(r'Username:')
  19. child.sendline(username)
  20. child.expect(r'Password:')
  21. child.sendline(password)
  22. child.expect(r'Connected (\w+) as (\d+\.\d+\.\d+\.\d+), using SSL')
  23. ip_address = child.match.group(2)
  24. tunnel_name = child.match.group(1)
  25. print "Detected IP address for tunnel", tunnel_name, "with IP address", ip_address
  26. child.interact()
  27. print "Copying file", pekkaniska_vpn_conf_file, "to", resolv_conf_file
  28. shutil.copyfile(pekkaniska_vpn_conf_file, resolv_conf_file)
  29.  
  30. add_net_command = add_net_template % (ip_address, tunnel_name)
  31. print "calling:", add_net_command
  32. add_net_output = commands.getoutput(add_net_command)
  33. print "output:", add_net_output
  34.  
  35. add_host_command = add_host_template % (ip_address)
  36. print "calling:", add_host_command
  37. add_host_output = commands.getoutput(add_host_command)
  38. print "output:", add_host_output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement