************************************* Lab 1 - Basic Python - If Statements ************************************* abc=input("Enter a number: ") abc=int(abc) if (abc > 99): print("The number you entered is larger than 99") print("Thanks for using the program") elif (abc < 99) : print("The number you entered is less than 99") print("Thanks for using the program") else: print("The number you entered is 99") print("Thanks for using the program") ************************************* Lab 2 - Basic Python - While Loops ************************************* abc=input("Enter a number: ") abc=int(abc) while abc > 0: print(abc) abc=abc-1 ************************************* Lab 3 - Executing a Show Command ************************************* from telnetlib import Telnet abc=input('Enter the Command : ') abccmd=abc + '\n' mytel=Telnet('172.25.1.1') mytel.write(b'khawar\n') mytel.write(b'cisco\n') mytel.write(b'terminal length 0\n') mytel.write(abccmd.encode('ascii')) mytel.write(b'exit\n') print(mytel.read_all().decode('ascii')) **************************************************** Lab 4 - Configuring an Interface - Static **************************************************** from telnetlib import Telnet ab = Telnet('172.25.1.1') ab.write(b'khawar\n') ab.write(b'cisco\n') ab.write(b'config t\n') ab.write(b'Interface Loopback55\n') ab.write(b'ip address 55.5.5.5 255.255.255.0\n') ab.write(b'end\n') ab.write(b'sh ip int brief\n') ab.write(b'exit\n') print (ab.read_all().decode('ascii')) **************************************************** Lab 5 - Configuring an Interface - Interactive **************************************************** from telnetlib import Telnet print(70*'*') print('Connection Information') print(70*'*') HOST = input('\nSpecify the Host IP : ') HOST = HOST + '\n' USER = input('Specify the Username: ') USER = USER + '\n' PASS = input('Specify the Password: ') PASS = PASS + '\n' print(70*'*') print('Interface Information') print(70*'*') Interface = input('\nWhat Interface would you like to configure [Loopback111,E0/0]: ') Ipaddr = input('Specify the IP Address : ') SMask = input('Specify the Subnet mask : ') ab = Telnet(HOST) ab.write(USER.encode('ascii')) ab.write(PASS.encode('ascii')) int_cmd = 'Interface ' + Interface + '\n' ipaddr_cmd = 'IP Address ' + Ipaddr + ' ' + SMask + '\n' ab.write(b'config t\n') ab.write(int_cmd.encode('ascii')) ab.write(ipaddr_cmd.encode('ascii')) ab.write(b'no shut\n') ab.write(b'end\n') ab.write(b'sh ip int brief\n') ab.write(b'exit\n') print (ab.read_all().decode('ascii')) **************************************************** Lab 6 - Creating Users **************************************************** from telnetlib import Telnet print(70*'*') print('Connection Information') print(70*'*') HOST = input('Specify the Host IP : ') USER = input('Specify the Username: ') PASS = input('Specify the Password: ') print(70*'*') print('User Information') print(70*'*') num_users = input('How many users would you like to create: ') num_users = int(num_users) ab = Telnet(HOST) ab.write(USER.encode('ascii') + b'\n') ab.write(PASS.encode('ascii') + b'\n') ab.write(b'config t\n') while (num_users > 0): username = input('Specify the Username to be created : ') userpass = input('Specify the Password: ') user_cmd='Username ' + username + ' privilege 15 password ' + userpass + '\n' ab.write(user_cmd.encode('ascii')) num_users -= 1 ab.write(b'end\n') ab.write(b'sh run | inc username\n') ab.write(b'exit\n') print (ab.read_all().decode('ascii'))