Back to Browse

Python learning for Network Engineers | Part 11 | devices lists explained

7.0K views
Mar 14, 2019
11:47

๐—™๐—ผ๐—ฟ ๐—–๐—ผ๐—บ๐—ฝ๐—น๐—ฒ๐˜๐—ฒ ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—™๐—ผ๐—ฟ ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ๐˜€ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ: ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—ณ๐—ผ๐—ฟ ๐—ฏ๐—ฒ๐—น๐—ผ๐˜„ ๐—จ๐—ฑ๐—ฒ๐—บ๐˜† ๐—–๐—น๐—ฎ๐˜€๐˜€: ๐Ÿ๐ŸŽ๐Ÿ๐Ÿ ๐•๐ž๐ซ๐ฌ๐ข๐จ๐ง ๐‘ซ๐’Š๐’”๐’„๐’๐’–๐’๐’•๐’†๐’… ๐‘น๐’†๐’‡๐’†๐’“๐’“๐’‚๐’ ๐‘ณ๐’Š๐’๐’Œ: https://www.udemy.com/course/python-for-network-engineers/?referralCode=35A75AAE1ACA94A15829 Lists are mutable objects: That means its value can be change after it is created Lists will be created in square brackets,values wil be separated using data import paramiko import time from getpass import getpass username = 'admin' password = 'admin' DEVICE_LIST =['10.10.10.' + str(n) for n in range(10,12)] for RTR in DEVICE_LIST: print ('\n #### Connecting to the device ' + RTR + '####\n' ) SESSION = paramiko.SSHClient() SESSION.set_missing_host_key_policy(paramiko.AutoAddPolicy()) SESSION.connect(RTR,port=22, username=username, password=password, look_for_keys=False, allow_agent=False) DEVICE_ACCESS = SESSION.invoke_shell() DEVICE_ACCESS.send(b'config t\n') for N in range (2,5): DEVICE_ACCESS.send('int lo ' +str(N) + '\n') DEVICE_ACCESS.send('ip address 1.1.1.' +str(N) + ' 255.255.255.255\n') time.sleep(3) DEVICE_ACCESS.send(b'do term length 0\n') DEVICE_ACCESS.send(b'do show ip int brief\n') time.sleep(3) output = DEVICE_ACCESS.recv(65000) print (output.decode('ascii')) SESSION.close DEVICE_LIST = ['10.10.10.10','10.10.10.11'] for RTR in DEVICE_LIST: print (RTR) DEVICE_LIST = ['10.10.10.'+ str(n) for n in range(10,15)] for RTR in DEVICE_LIST: print (RTR) python help() - topics help SEQUENCES - LISTS interface = ['Gi'+str(n) for n in range(2,5)] list comprehension Indexing DEVICE_LIST = ['10.10.10.10','10.10.10.11','R1'] print (DEVICE_LIST[0]) some of the operations type(devices) dir(devices) devices.append('SW4') DEVICE_LIST = ['10.10.10.10','10.10.10.11'] DEVICE_LIST = ['10.10.10.'+ str(n) for n in range(10,15)] for RTR in DEVICE_LIST: ip = "10.10.10." + str(n)

Download

0 formats

No download links available.

Python learning for Network Engineers | Part 11 | devices lists explained | NatokHD