cisco_wifi_ctl.py : configurable prompt

This commit is contained in:
Chuck SmileyRekiere
2020-12-10 18:47:27 -07:00
parent 0df232e940
commit f5d998d49e

View File

@@ -14,7 +14,7 @@ $ pip3 install pexpect-serial
./cisco_wifi_ctl.py -d 172.19.27.95 -o 2013 -l stdout -a AxelMain -u cisco -p Cisco123 -s telnet
# For LANforge lab system.
./cisco_wifi_ctl.py --scheme ssh -d 192.168.100.112 -u admin -p Cisco123 --action summary --prompt "\(Cisco Controller\) >"
./cisco_wifi_ctl.py --scheme ssh -d 192.168.100.112 -u admin -p Cisco123 --action summary --prompt "\(Cisco Controller\)"
./cisco_wifi_ctl.py --scheme ssh -d 192.168.100.112 -u admin -p Cisco123 --action cmd --value "show ap config general APA453.0E7B.CF9C"
telnet 172.19.36.168(Pwd:), go to the privileged mode and execute the command “clear line 43”.
@@ -92,8 +92,8 @@ def main():
parser = argparse.ArgumentParser(description="Cisco AP Control Script")
parser.add_argument("-d", "--dest", type=str, help="address of the cisco controller")
parser.add_argument("-o", "--port", type=int, help="control port on the controller")
parser.add_argument("--prompt", type=str, help="Prompt to expect", default="(Cisco Controller) >")
parser.add_argument("--series", type=str, help="cisco controller series",default="3504")
parser.add_argument("--prompt", type=str, help="Prompt to expect", default="WLC")
parser.add_argument("--series", type=str, help="cisco controller series",default="9800")
parser.add_argument("-u", "--user", type=str, help="credential login/username")
parser.add_argument("-p", "--passwd", type=str, help="credential password")
parser.add_argument("-s", "--scheme", type=str, choices=["serial", "ssh", "telnet"], help="Connect via serial, ssh or telnet")
@@ -153,6 +153,23 @@ def main():
print("cisco series {}".format(args.series))
print("scheme {}".format(args.scheme))
CCPROMPT = args.prompt + " >" #'\(Voice-Talwar\) >'
LOGOUTPROMPT = 'User:'
EXITPROMPT = "Would you like to save them now? (y/N)"
AREYOUSURE = "Are you sure you want to continue? (y/n)"
CLOSEDBYREMOTE = "closed by remote host."
CLOSEDCX = "Connection to .* closed."
# 9800 series PROMPTS
CCP = args.prompt + ">" # WLC>
CCP_EN = args.prompt + "#" # WLC#
CCP_CONFIG = args.prompt + "(config)#" #WLC(config)#
CCP_CONFIG_WLAN = args.prompt + "(config-wlan)#" #WLC(config- wlan)#
CCP_POLICY_TAG = args.prompt + "(config-policy-tag)#" #WLC(config-policy-tag)#
CCP_CONFIG_LINE = args.prompt + "(config-line)#" #WLC(config-line)#
try:
if (scheme == "serial"):
#eggspect = pexpect.fdpexpect.fdspan(telcon, logfile=sys.stdout.buffer)
@@ -192,7 +209,7 @@ def main():
egg.sendline(CR)
sleep(0.4)
try:
i = egg.expect_exact(["Escape character is '^]'.","WLC>","WLC#","User:","Password:","WLC(config)#","Bad secrets",pexpect.TIMEOUT],timeout=2)
i = egg.expect_exact(["Escape character is '^]'.","CCP","CCP_EN","User:","Password:","CCP_CONFIG","Bad secrets",pexpect.TIMEOUT],timeout=2)
except Exception as e:
logg.info('connection failed. or refused Connection open by other process')
logging.exception(e)
@@ -203,10 +220,10 @@ def main():
#egg.sendline(CR)
found_escape = True
sleep(0.1)
j = egg.expect_exact(["WLC>","WLC#","User:","Password:","WLC(config)#",pexpect.TIMEOUT],timeout=3)
j = egg.expect_exact(["CCP","CCP_EN","User:","Password:","CCP_CONFIG",pexpect.TIMEOUT],timeout=3)
sleep(0.1)
if j == 0:
logg.info("9800 found WLC> will elevate loging i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after))
logg.info("9800 found CCP will elevate loging i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after))
egg.sendline("en")
sleep(0.1)
k = egg.expect_exact(["Password:",pexpect.TIMEOUT], timeout=2)
@@ -214,7 +231,7 @@ def main():
logg.info("9800 received password prompt will send password: {} i:{} j:{} k:{} before {} after {}".format(args.passwd,i,j,k,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
l = egg.expect_exact(["WLC#",pexpect.TIMEOUT],timeout=2)
l = egg.expect_exact(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if l == 0:
logg.info("9800 Successfully received # prompt i:{} j:{} k:{} l:{}".format(i,j,k,l))
logged_in_9800 = True
@@ -234,7 +251,7 @@ def main():
logg.info("9800 received password prompt after sending User, sending password: {} i:{} j:{} k:{}".format(args.passwd,i,j,k))
egg.sendline(args.passwd)
sleep(0.1)
l = egg.expect_exact(["WLC#",pexpect.TIMEOUT],timeout=2)
l = egg.expect_exact(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if l == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{} l:{}".format(i,j,k,l))
logged_in_9800 = True
@@ -247,20 +264,20 @@ def main():
logg.info("9800 received Password prompt will send password {} i:{} j:{} before {} after {}".format(args.passwd,i,j,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
k = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
k = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if k == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
logged_in_9800 = True
if k == 1:
logg.info("9800 Timed out waiting for # prompt i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
if j == 4:
logg.info("9800 received WLC(config)# prompt doing some cleanup")
logg.info("9800 received CCP_CONFIG prompt doing some cleanup")
egg.sendline("exit")
sleep(0.1)
k = egg.expect_exact(["WLC>","WLC#","User:","Password:",pexpect.TIMEOUT],timeout=3)
k = egg.expect_exact(["CCP","CCP_EN","User:","Password:",pexpect.TIMEOUT],timeout=3)
sleep(0.1)
if k == 0:
logg.info("9800 found WLC> will elevate loging i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
logg.info("9800 found CCP will elevate loging i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
egg.sendline("en")
sleep(0.1)
l = egg.expect_exact(["Password:",pexpect.TIMEOUT], timeout=2)
@@ -268,7 +285,7 @@ def main():
logg.info("9800 received password prompt will send password: {} i:{} j:{} k:{} l:{} before {} after {}".format(args.passwd,i,j,k,l,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
m = egg.expect_exact(["WLC#",pexpect.TIMEOUT],timeout=2)
m = egg.expect_exact(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if m == 0:
logg.info("9800 Successfully received # prompt i:{} j:{} k:{} l:{} m:{}".format(i,j,k,l,m))
logged_in_9800 = True
@@ -288,7 +305,7 @@ def main():
logg.info("9800 received password prompt after sending User, sending password: {} i:{} j:{} k:{} l:{}".format(args.passwd,i,j,k,l))
egg.sendline(args.passwd)
sleep(0.1)
m = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
m = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if m == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{} l:{} m:{}".format(i,j,k,l,m))
logged_in_9800 = True
@@ -301,14 +318,14 @@ def main():
logg.info("9800 received Password prompt will send password {} i:{} j:{} k:{} before {} after {}".format(args.passwd,i,j,k,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
l = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
l = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if l == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{} l:{} before {} after {}".format(i,j,k,l,egg.before,egg.after))
logged_in_9800 = True
if l == 1:
logg.info("9800 Timed out waiting for # prompt i:{} j:{} k:{} l:{} before {} after {}".format(i,j,k,l,egg.before,egg.after))
if k == 4:
logg.info("9800 timed out looking WLC>, WLC#, User:, Password: i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
logg.info("9800 timed out looking {}, {}, User:, Password: i:{} j:{} k:{} before {} after {}".format(CCP,CCP_EN,i,j,k,egg.before,egg.after))
logg.info("9800 Timed out waiting for initial prompt send logout loop_count: {} i: {} j: {} k:{} before {} after {}".format(loop_count, i, j, k, egg.before,egg.after))
logg.info("9800 Closing the connection and try to re-establish, ")
egg.close(force = True)
@@ -326,7 +343,7 @@ def main():
found_escape = False
if j == 5:
logg.info("9800 timed out looking for WLC>,WLC#,User:,Password:,WLC(config)# loop_count {} i {} j {} before {} after {}".format(loop_count,i,j,egg.before,egg.after))
logg.info("9800 timed out looking for CCP,CCP_EN,User:,Password:,CCP_CONFIG loop_count {} i {} j {} before {} after {}".format(CCP,CCP_EN,CCP_CONFIG,loop_count,i,j,egg.before,egg.after))
logg.info("9800 Closing the connection and try to re-establish loop_count {} i {} j {}".format(loop_count,i,j))
egg.close(force = True)
sleep(1)
@@ -343,7 +360,7 @@ def main():
found_escape = False
if i == 1:
logg.info("9800 found WLC> will elevate loging i:{} before {} after {}".format(i,egg.before,egg.after))
logg.info("9800 found {} will elevate loging i:{} before {} after {}".format(CCP,i,egg.before,egg.after))
egg.sendline("en")
sleep(0.1)
j = egg.expect_exact(["Password:",pexpect.TIMEOUT], timeout=2)
@@ -351,7 +368,7 @@ def main():
logg.info("9800 received password prompt will send password: {} i:{} j:{} before {} after {}".format(args.passwd,i,j, egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
k = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
k = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if k == 0:
logg.info("9800 Successfully received # prompt i:{} j:{} k:{} before {} after {}".format(i,j,k, egg.before,egg.after))
logged_in_9800 = True
@@ -361,7 +378,7 @@ def main():
logg.info("8900 received timeout after looking for password: prompt i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
if i == 2:
logg.info("9800 found WLC# This implies in incorrect logout or killed prior run test i:{} before {} after {}".format(i,egg.before,egg.after))
logg.info("9800 found {} This implies in incorrect logout or killed prior run test i:{} before {} after {}".format(CCP_EN,i,egg.before,egg.after))
logged_in_9800 = True
if i == 3:
@@ -373,7 +390,7 @@ def main():
logg.info("9800 received password prompt after sending User, sending password: {} i:{} j:{} before {} after {}".format(args.passwd,i,k,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
l = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
l = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if k == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{}".format(i,j,k))
logged_in_9800 = True
@@ -386,7 +403,7 @@ def main():
logg.info("9800 received password prompt will send password: {} i:{} before {} after {}".format(args.passwd,i,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
j = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
j = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if j == 0:
logg.info("9800 Successfully received # prompt i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after))
logged_in_9800 = True
@@ -394,13 +411,13 @@ def main():
logg.info("9800 Timed out waiting for # prompt i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after))
if i == 5:
logg.info("9800 received WLC(config)# prompt doing some cleanup")
logg.info("9800 received {} prompt doing some cleanup".format(CCP_CONFIG))
egg.sendline("exit")
sleep(0.1)
j = egg.expect_exact(["WLC>","WLC#","User:","Password:",pexpect.TIMEOUT],timeout=3)
j = egg.expect_exact(["CCP","CCP_EN","User:","Password:",pexpect.TIMEOUT],timeout=3)
sleep(0.1)
if j == 0:
logg.info("9800 found WLC> will elevate loging i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after))
logg.info("9800 found {} will elevate loging i:{} j:{} before {} after {}".format(CCP,i,j,egg.before,egg.after))
egg.sendline("en")
sleep(0.1)
k = egg.expect_exact(["Password:",pexpect.TIMEOUT], timeout=2)
@@ -408,7 +425,7 @@ def main():
logg.info("9800 received password prompt will send password: {} i:{} j:{} k:{} before {} after {}".format(args.passwd,i,j,k,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
l = egg.expect_exact(["WLC#",pexpect.TIMEOUT],timeout=2)
l = egg.expect_exact(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if l == 0:
logg.info("9800 Successfully received # prompt i:{} j:{} k:{} l:{}".format(i,j,k,l))
logged_in_9800 = True
@@ -428,7 +445,7 @@ def main():
logg.info("9800 received password prompt after sending User, sending password: {} i:{} j:{} k:{}".format(args.passwd,i,j,k))
egg.sendline(args.passwd)
sleep(0.1)
l = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
l = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if l == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{} l:{}".format(i,j,k,l))
logged_in_9800 = True
@@ -441,14 +458,14 @@ def main():
logg.info("9800 received Password prompt will send password {} i:{} j:{} before {} after {}".format(args.passwd,i,j,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
k = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
k = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if k == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
logged_in_9800 = True
if k == 1:
logg.info("9800 Timed out waiting for # prompt i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
if j == 4:
logg.info("9800 timed out looking WLC>, WLC#, User:, Password: i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after))
logg.info("9800 timed out looking {}, {}, User:, Password: i:{} j:{} before {} after {}".format(CCP, CCP_EN,i,j,egg.before,egg.after))
logg.info("9800 Timed out waiting for initial prompt send logout loop_count: {} i: {} j: {} before {} after {}".format(loop_count, i, j, egg.before,egg.after))
logg.info("9800 Closing the connection and try to re-establish, ")
egg.close(force = True)
@@ -536,7 +553,7 @@ def main():
egg.sendline(CR)
sleep(0.4)
try:
i = egg.expect_exact(["Escape character is '^]'.","WLC>","WLC#","User:","Password:","WLC(config)#","Bad secrets", PRESS_RETURN, CONFIG_I,pexpect.TIMEOUT],timeout=2)
i = egg.expect_exact(["Escape character is '^]'.","CCP","CCP_EN","User:","Password:","CCP_CONFIG","Bad secrets", PRESS_RETURN, CONFIG_I,pexpect.TIMEOUT],timeout=2)
except Exception as e:
logg.info('connection failed. or refused Connection open by other process')
logg.exception(e)
@@ -547,10 +564,10 @@ def main():
#egg.sendline(CR)
found_escape = True
sleep(0.1)
j = egg.expect_exact(["WLC>","WLC#","User:","Password:",pexpect.TIMEOUT],timeout=3)
j = egg.expect_exact(["CCP","CCP_EN","User:","Password:",pexpect.TIMEOUT],timeout=3)
sleep(0.1)
if j == 0:
logg.info("9800 found WLC> will elevate loging i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after))
logg.info("9800 found {} will elevate loging i:{} j:{} before {} after {}".format(CCP,i,j,egg.before,egg.after))
egg.sendline("en")
sleep(0.1)
k = egg.expect_exact(["Password:",pexpect.TIMEOUT], timeout=2)
@@ -558,9 +575,9 @@ def main():
logg.info("9800 received password prompt will send password: {} i:{} j:{} k:{} before {} after {}".format(args.passwd,i,j,k,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
l = egg.expect_exact(["WLC#",pexpect.TIMEOUT],timeout=2)
l = egg.expect_exact(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if l == 0:
logg.info("9800 Successfully received WLC# prompt i:{} j:{} k:{} l:{}".format(i,j,k,l))
logg.info("9800 Successfully received {} prompt i:{} j:{} k:{} l:{}".format(CCP_EN,i,j,k,l))
logged_in_9800 = True
if l == 1:
logg.info("9800 Timed out waiting for # prompt i:{} j:{} k:{} l:{} before {} after {}".format(i,j,k,l,egg.before,egg.after))
@@ -578,7 +595,7 @@ def main():
logg.info("9800 received password prompt after sending User, sending password: {} i:{} j:{} k:{}".format(args.passwd,i,j,k))
egg.sendline(args.passwd)
sleep(0.1)
l = egg.expect_exact(["WLC#",pexpect.TIMEOUT],timeout=2)
l = egg.expect_exact(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if l == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{} l:{}".format(i,j,k,l))
logged_in_9800 = True
@@ -591,20 +608,20 @@ def main():
logg.info("9800 received Password prompt will send password {} i:{} j:{} before {} after {}".format(args.passwd,i,j,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
k = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
k = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if k == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
logged_in_9800 = True
if k == 1:
logg.info("9800 Timed out waiting for # prompt i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
if j == 4:
logg.info("9800 received WLC(config)# prompt doing some cleanup")
logg.info("9800 received {} prompt doing some cleanup".format(CCP_CONFIG))
egg.sendline("exit")
sleep(0.1)
k = egg.expect_exact(["WLC>","WLC#","User:","Password:",pexpect.TIMEOUT],timeout=3)
k = egg.expect_exact(["CCP","CCP_EN","User:","Password:",pexpect.TIMEOUT],timeout=3)
sleep(0.1)
if k == 0:
logg.info("9800 found WLC> will elevate loging i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
logg.info("9800 found {} will elevate loging i:{} j:{} k:{} before {} after {}".format(CCP,i,j,k,egg.before,egg.after))
egg.sendline("en")
sleep(0.1)
l = egg.expect_exact(["Password:",pexpect.TIMEOUT], timeout=2)
@@ -612,7 +629,7 @@ def main():
logg.info("9800 received password prompt will send password: {} i:{} j:{} k:{} l:{} before {} after {}".format(args.passwd,i,j,k,l,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
m = egg.expect_exact(["WLC#",pexpect.TIMEOUT],timeout=2)
m = egg.expect_exact(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if m == 0:
logg.info("9800 Successfully received # prompt i:{} j:{} k:{} l:{} m:{}".format(i,j,k,l,m))
logged_in_9800 = True
@@ -632,7 +649,7 @@ def main():
logg.info("9800 received password prompt after sending User, sending password: {} i:{} j:{} k:{} l:{}".format(args.passwd,i,j,k,l))
egg.sendline(args.passwd)
sleep(0.1)
m = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
m = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if m == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{} l:{} m:{}".format(i,j,k,l,m))
logged_in_9800 = True
@@ -645,14 +662,14 @@ def main():
logg.info("9800 received Password prompt will send password {} i:{} j:{} k:{} before {} after {}".format(args.passwd,i,j,k,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
l = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
l = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if l == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{} l:{} before {} after {}".format(i,j,k,l,egg.before,egg.after))
logged_in_9800 = True
if l == 1:
logg.info("9800 Timed out waiting for # prompt i:{} j:{} k:{} l:{} before {} after {}".format(i,j,k,l,egg.before,egg.after))
if k == 4:
logg.info("9800 timed out looking WLC>, WLC#, User:, Password: i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
logg.info("9800 timed out looking {}, {}, User:, Password: i:{} j:{} k:{} before {} after {}".format(CCP, CCP_EN, i,j,k,egg.before,egg.after))
logg.info("9800 Timed out waiting for initial prompt send logout loop_count: {} i: {} j: {} k:{} before {} after {}".format(loop_count, i, j, k, egg.before,egg.after))
logg.info("9800 Closing the connection and try to re-establish, ")
egg.close(force = True)
@@ -670,7 +687,7 @@ def main():
found_escape = False
if j == 5:
logg.info("9800 timed out looking for WLC>,WLC#,User:,Password: loop_count {} i {} j {} before {} after {}".format(loop_count,i,j,egg.before,egg.after))
logg.info("9800 timed out looking for {}, {},User:,Password: loop_count {} i {} j {} before {} after {}".format(CCP,CCP_EN,loop_count,i,j,egg.before,egg.after))
logg.info("9800 Closing the connection and try to re-establish loop_count {} i {} j {}".format(loop_count,i,j))
egg.close(force = True)
sleep(1)
@@ -679,7 +696,7 @@ def main():
if i == 1:
logg.info("9800 found WLC> will elevate loging i:{} before {} after {}".format(i,egg.before,egg.after))
logg.info("9800 found {} will elevate loging i:{} before {} after {}".format(CCP,i,egg.before,egg.after))
egg.sendline("en")
sleep(0.1)
j = egg.expect_exact(["Password:",pexpect.TIMEOUT], timeout=2)
@@ -687,7 +704,7 @@ def main():
logg.info("9800 received password prompt will send password: {} i:{} j:{} before {} after {}".format(args.passwd,i,j, egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
k = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
k = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if k == 0:
logg.info("9800 Successfully received # prompt i:{} j:{} k:{} before {} after {}".format(i,j,k, egg.before,egg.after))
logged_in_9800 = True
@@ -697,7 +714,7 @@ def main():
logg.info("8900 received timeout after looking for password: prompt i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
if i == 2:
logg.info("9800 found WLC# This implies in incorrect logout or killed prior run test i:{} before {} after {}".format(i,egg.before,egg.after))
logg.info("9800 found {} This implies in incorrect logout or killed prior run test i:{} before {} after {}".format(CCP_EN,i,egg.before,egg.after))
logged_in_9800 = True
if i == 3:
@@ -709,7 +726,7 @@ def main():
logg.info("9800 received password prompt after sending User, sending password: {} i:{} j:{} before {} after {}".format(args.passwd,i,j,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
l = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
l = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if k == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{}".format(i,j,k))
logged_in_9800 = True
@@ -722,7 +739,7 @@ def main():
logg.info("9800 received password prompt will send password: {} i:{} before {} after {}".format(args.passwd,i, egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
j = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
j = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if j == 0:
logg.info("9800 Successfully received # prompt i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after))
logged_in_9800 = True
@@ -730,13 +747,13 @@ def main():
logg.info("9800 Timed out waiting for # prompt i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after))
if i == 5:
logg.info("9800 received WLC(config)# prompt doing some cleanup")
logg.info("9800 received {} prompt doing some cleanup".format(CCP_CONFIG))
egg.sendline("exit")
sleep(0.3)
j = egg.expect_exact(["WLC>","WLC#","User:","Password:",pexpect.TIMEOUT],timeout=3)
j = egg.expect_exact(["CCP","CCP_EN","User:","Password:",pexpect.TIMEOUT],timeout=3)
sleep(0.1)
if j == 0:
logg.info("9800 found WLC> will elevate loging i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after))
logg.info("9800 found CCP will elevate loging i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after))
egg.sendline("en")
sleep(0.1)
k = egg.expect_exact(["Password:",pexpect.TIMEOUT], timeout=2)
@@ -744,7 +761,7 @@ def main():
logg.info("9800 received password prompt will send password: {} i:{} j:{} k:{} before {} after {}".format(args.passwd,i,j,k,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
l = egg.expect_exact(["WLC#",pexpect.TIMEOUT],timeout=2)
l = egg.expect_exact(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if l == 0:
logg.info("9800 Successfully received # prompt i:{} j:{} k:{} l:{}".format(i,j,k,l))
logged_in_9800 = True
@@ -764,7 +781,7 @@ def main():
logg.info("9800 received password prompt after sending User, sending password: {} i:{} j:{} k:{}".format(args.passwd,i,j,k))
egg.sendline(args.passwd)
sleep(0.1)
l = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
l = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if l == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{} l:{}".format(i,j,k,l))
logged_in_9800 = True
@@ -777,14 +794,14 @@ def main():
logg.info("9800 received Password prompt will send password {} i:{} j:{} before {} after {}".format(args.passwd,i,j,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.1)
k = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
k = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if k == 0:
logg.info("8900 Successfully received # prompt i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
logged_in_9800 = True
if k == 1:
logg.info("9800 Timed out waiting for # prompt i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after))
if j == 4:
logg.info("9800 timed out looking WLC>, WLC#, User:, Password: i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after))
logg.info("9800 timed out looking {}, {}, User:, Password: i:{} j:{} before {} after {}".format(CCP,CCP_EN,i,j,egg.before,egg.after))
logg.info("9800 Timed out waiting for initial prompt send logout loop_count: {} i: {} j: {} before {} after {}".format(loop_count, i, j, egg.before,egg.after))
logg.info("9800 Closing the connection and try to re-establish, ")
egg.close(force = True)
@@ -832,12 +849,12 @@ def main():
if loop_count >= 8:
if found_escape == True:
logg.info("9800 outside major loop loop_count {}".format(loop_count))
logg.info("9800 will look one more time for WLC#")
logg.info("9800 will look one more time for {}".format(CCP_EN))
egg.sentline(CR)
sleep(0.2)
r = egg.expect_exact(["WLC#",pexpect.TIMEOUT],timeout=3)
r = egg.expect_exact(["CCP_EN",pexpect.TIMEOUT],timeout=3)
if r == 0:
logg.info("Found WLC# r {} before {} after {} can move forward".format(r,egg.before,egg.after))
logg.info("Found {} r {} before {} after {} can move forward".format(CCP_EN,r,egg.before,egg.after))
if r == 1:
egg.sendline("\x1b\r")
egg.sendline("logout")
@@ -858,7 +875,7 @@ def main():
egg.sendline(user)
egg.expect('Password\:',timeout=3)
egg.sendline(passwd)
#if args.prompt in "WLC#" or args.prompt in "WLC>":
#if args.prompt in "CCP_EN" or args.prompt in "CCP":
# egg.sendline("enable")
# time.sleep(0.1)
egg.sendline('config paging disable')
@@ -877,20 +894,14 @@ def main():
command = None
time.sleep(0.1)
CCPROMPT = args.prompt #'\(Voice-Talwar\) >'
LEGACY_PROMPT = "(cisco) >"
LOGOUTPROMPT = 'User:'
EXITPROMPT = "Would you like to save them now? (y/N)"
AREYOUSURE = "Are you sure you want to continue? (y/n)"
CLOSEDBYREMOTE = "closed by remote host."
CLOSEDCX = "Connection to .* closed."
sleep(0.1)
if args.series == "9800":
pass
else:
#TODO clean up
logg.info("waiting for prompt: {} or {} ".format(CCPROMPT,LEGACY_PROMPT))
logg.info("waiting for prompt: {}".format(CCPROMPT))
egg.expect(">", timeout=3)
logg.info("Ap[%s] Action[%s] Value[%s] "%(args.ap, args.action, args.value))
@@ -1092,7 +1103,7 @@ def main():
for command in ["wireless tag policy default-policy-tag","no wlan open-wlan policy default-policy-profile"]:
egg.sendline(command)
sleep(1)
j = egg.expect_exact(["(config-policy-tag)#",pexpect.TIMEOUT],timeout=2)
j = egg.expect_exact([CCP_POLICY_TAG,pexpect.TIMEOUT],timeout=2)
if j == 0:
logg.info("command sent: {}".format(command))
if j == 1:
@@ -1110,7 +1121,7 @@ def main():
for command in ["wireless tag policy default-policy-tag","wlan open-wlan policy default-policy-profile"]:
egg.sendline(command)
sleep(1)
j = egg.expect_exact(["(config-policy-tag)#",pexpect.TIMEOUT],timeout=2)
j = egg.expect_exact([CCP_POLICY_TAG,pexpect.TIMEOUT],timeout=2)
if j == 0:
logg.info("command sent: {}".format(command))
if j == 1:
@@ -1164,7 +1175,7 @@ def main():
if (args.action == "show_wlan_summary"):
egg.sendline("show wlan summary")
sleep(0.1)
i = egg.expect(["WLC#",pexpect.TIMEOUT],timeout=2)
i = egg.expect(["CCP_EN",pexpect.TIMEOUT],timeout=2)
if i == 0:
logg.info("show wlan summary sent")
if i == 1:
@@ -1183,13 +1194,13 @@ def main():
logg.info("open network command {}".format(command))
egg.sendline(command)
sleep(0.4)
j = egg.expect_exact(["WLC(config-wlan)#",pexpect.TIMEOUT],timeout=2)
j = egg.expect_exact(["CCP_CONFIG_WLAN",pexpect.TIMEOUT],timeout=2)
if j == 0:
for command in ["shutdown","no security ft","no security wpa","no security wpa wpa2","no security wpa wpa2 ciphers aes",
"no security wpa akm dot1x","no shutdown"]:
egg.sendline(command)
sleep(1)
k = egg.expect_exact(["WLC(config-wlan)#",pexpect.TIMEOUT],timeout=2)
k = egg.expect_exact(["CCP_CONFIG_WLAN",pexpect.TIMEOUT],timeout=2)
if k == 0:
logg.info("command sent: {}".format(command))
if k == 1:
@@ -1273,16 +1284,16 @@ def main():
loop_count = 0
while logged_out_9800 == False and loop_count <= 6:
loop_count += 1
i = egg.expect_exact(["WLC>","WLC#", "WLC(config)#","(config-wlan)#","(config-policy-tag)#","(config-line)#",pexpect.TIMEOUT],timeout=5)
i = egg.expect_exact(["CCP","CCP_EN", "CCP_CONFIG","(config-wlan)#",CCP_POLICY_TAG,CCP_POLICY_TAG,pexpect.TIMEOUT],timeout=5)
print (egg.before.decode('utf-8', 'ignore'))
if i == 0:
logg.info("WLC> prompt received can send logout")
logg.info("{} prompt received can send logout".format(CCP))
egg.sendline("logout")
sleep(0.1)
logged_out_9800 = True
break
if i == 1:
logg.info("WLC# prompt received will send logout")
logg.info("{} prompt received will send logout".format(CCP_EN))
try:
egg.sendline("logout")
sleep(0.1)
@@ -1292,7 +1303,7 @@ def main():
sleep(0.1)
break
if i == 2:
logg.info("WLC(config)# prompt received will send exit")
logg.info("{} prompt received will send exit".format(CCP_CONFIG))
try:
egg.sendline("exit")
sleep(0.2)
@@ -1300,7 +1311,7 @@ def main():
logg.info("9800 exception on exit")
sleep(0.1)
if i == 3:
logg.info("WLC(config-wlan)# prompt received will send exit")
logg.info("{} prompt received will send exit".format(CCP_CONFIG_WLAN))
try:
egg.sendline("exit")
sleep(0.2)
@@ -1316,7 +1327,7 @@ def main():
logg.info("9800 exception on exit")
sleep(0.1)
if i == 5:
logg.info("(config-line)# prompt received will send exit")
logg.info("{} prompt received will send exit".format(CCP_CONFIG_LINE))
try:
egg.sendline("exit")
sleep(0.2)
@@ -1352,18 +1363,14 @@ def main():
while command_sent == False and loop_count <= 3:
loop_count += 1
try:
i = egg.expect_exact([CCPROMPT,LEGACY_PROMPT,AREYOUSURE,'--More-- or','config paging disable',pexpect.TIMEOUT],timeout=2)
i = egg.expect_exact([CCPROMPT,AREYOUSURE,'--More-- or','config paging disable',pexpect.TIMEOUT],timeout=2)
logg.info("before {} after {}".format(egg.before.decode('utf-8', 'ignore'),egg.after.decode('utf-8', 'ignore')))
print(egg.before.decode('utf-8', 'ignore'))
if i == 0:
logg.info("{} prompt received after command sent".format(CCPROMPT))
# granted the break will exit the loop
command_sent = True
if i == 1:
logg.info("{} prompt received after command sent".format(LEGACY_PROMPT))
# granted the break will exit the loop
if loop_count > 2:
command_sent = True
if i == 2:
egg.sendline("y")
command_sent = True
@@ -1380,7 +1387,7 @@ def main():
command_sent = True
except:
logg.info("closing connection logout loop")
logg.info("closing connection logout loop {}".format(CCPROMPT))
try:
egg.sendline("logout")
logg.info("logout")