Created
August 28, 2013 19:06
-
-
Save Dieterbe/6369944 to your computer and use it in GitHub Desktop.
i needed to connect to a juniper network connect vpn, but i didn't know the exact format of username, realm, hostname, and i wasn't sure exactly which password.
this script uses Pexpect to try all combinations until it works.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# must be run from your ~/.juniper_networks otherwise you get: | |
# Failed to load the ncui library.\nQuitting. | |
# see also http://htnhan.blogspot.com/2013/07/juniper-network-connect-on-arch-linux.html | |
import pexpect | |
import time | |
from itertools import product | |
hosts = [''] | |
users = ['youruser' , '..'] | |
realms = ['-r foo', ..] | |
passes = [''] | |
error_104 = 'ncapp> Failed to connect/authenticate with IVE. Error 104' | |
error_hostname = 'Error unable to resolve host' | |
def test(combo): | |
host = combo[0] | |
user = combo[1] | |
realm = combo[2] | |
passw = combo[3] | |
cmd = "/opt/bin32-jre/bin/java -jar NC.jar -h %s -u %s -f <key>.der %s -L 5" % (host, user, realm) | |
print "TESTING", cmd | |
child = pexpect.spawn (cmd) | |
child.expect ('Password:') | |
time.sleep(0.1) | |
child.sendline (passw) | |
index = child.expect([error_104, pexpect.EOF, error_hostname]) | |
if index == 0: | |
print error_104 | |
elif index == 1: | |
print 'DUNNO!! what happend. output:' | |
print child.before | |
elif index == 2: | |
print error_hostname | |
for i, combo in enumerate(product(hosts, users, realms, passes)): | |
print "TESTING %i" % i, combo | |
test(combo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment