Hello there!
If you'd like to collect the data of all NEs in your network, you first need to know at least their login IP addresses and the login accounts. It is much easier if all NEs have the same account, such as the same SSH account. So you can use a loop statement to log in to each device in turn to collect information.
Script example:
# -*- coding:utf-8 -*-
import paramiko
import time
ssh = paramiko.SSHClient()
key = paramiko.AutoAddPolicy()
ssh.set_missing_host_key_policy(key)
def execute(addr):
ssh.connect(addr, 22, 'test', '123456', timeout=200) # The Username/Password of the SSH account.
ssh_shell = ssh.invoke_shell()
output =[]
for script in scripts:
ssh_shell.send(script)
output.append(ssh_shell.recv(2024).decode('utf-8'))
time.sleep(0.1)
return output
if __name__ == '__main__':
# Devices to execute scripts in batches
devices = ['10.1.1.1', '10.1.1.2', '10.1.1.3']
# Scripts to be executed in batches
# scripts = ['sys\n', 'sys sw\n', 'q\n', 'save\n', 'Y\n']
scripts = ['display esn', 'display ip interface brief']
# The display esn command displays the Equipment Serial Number (ESN) of a device.
# The display ip interface brief command displays brief information about interface IP addresses.
for device in devices:
res = execute(device)
print(res) # Here you've got the commands output. You can save the output to a file or use the re module to extract the information you want.