filmov
tv
Python learning for Network Engineers | Part 10 | using for loop range for devices

ะะพะบะฐะทะฐัั ะพะฟะธัะฐะฝะธะต
๐๐ผ๐ฟ ๐๐ผ๐บ๐ฝ๐น๐ฒ๐๐ฒ ๐ฃ๐๐๐ต๐ผ๐ป ๐๐ผ๐ฟ ๐ก๐ฒ๐๐๐ผ๐ฟ๐ธ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ๐ ๐๐ผ๐๐ฟ๐๐ฒ:
๐๐ป๐ฟ๐ผ๐น๐น ๐ณ๐ผ๐ฟ ๐ฏ๐ฒ๐น๐ผ๐ ๐จ๐ฑ๐ฒ๐บ๐ ๐๐น๐ฎ๐๐: ๐๐๐๐ ๐๐๐ซ๐ฌ๐ข๐จ๐ง
๐ซ๐๐๐๐๐๐๐๐๐ ๐น๐๐๐๐๐๐๐ ๐ณ๐๐๐:
Here I will be using two devices 10 and 11
import paramiko
import time
from getpass import getpass
username = 'admin'
password = 'admin'
for RTR in range(10,12):
ip = "10.10.10." + str(RTR)
print ('\n##### Connecting to the device ' + ip +' #####')
SESSION = paramiko.SSHClient()
SESSION.set_missing_host_key_policy(paramiko.AutoAddPolicy())
SESSION.connect(ip,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')
DEVICE_ACCESS.send(b'do term length 0\n')
DEVICE_ACCESS.send(b'do show ip int brief\n')
output = DEVICE_ACCESS.recv(65000)
SESSION.close
๐๐ป๐ฟ๐ผ๐น๐น ๐ณ๐ผ๐ฟ ๐ฏ๐ฒ๐น๐ผ๐ ๐จ๐ฑ๐ฒ๐บ๐ ๐๐น๐ฎ๐๐: ๐๐๐๐ ๐๐๐ซ๐ฌ๐ข๐จ๐ง
๐ซ๐๐๐๐๐๐๐๐๐ ๐น๐๐๐๐๐๐๐ ๐ณ๐๐๐:
Here I will be using two devices 10 and 11
import paramiko
import time
from getpass import getpass
username = 'admin'
password = 'admin'
for RTR in range(10,12):
ip = "10.10.10." + str(RTR)
print ('\n##### Connecting to the device ' + ip +' #####')
SESSION = paramiko.SSHClient()
SESSION.set_missing_host_key_policy(paramiko.AutoAddPolicy())
SESSION.connect(ip,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')
DEVICE_ACCESS.send(b'do term length 0\n')
DEVICE_ACCESS.send(b'do show ip int brief\n')
output = DEVICE_ACCESS.recv(65000)
SESSION.close
ะะพะผะผะตะฝัะฐัะธะธ