Thursday, July 26, 2018

python - netmiko

Hello,

I hope somebody can help me.
I'll write a script where I get output in a text file. One command output should safed for all switches in a network. if possible in one textfile per switch.

At the moment I have written following:

from netmiko import ConnectHandler

import sys

ip1 = {

"device_type":"hp_procurve",

"ip": "192.168.48.254",

"username":"Hendrik",

"password":"test"

}

net_connect = ConnectHandler(**ip1)

print ("Wait please")

print("sh tech all will be printed in file" )

# output in Datei sh_tech.txt

sys.stdout = open('sh_tech.txt', 'w')

sh_tech = net_connect.send_command("sh tech all")

print (sh_tech)

# sys.stdout.close()

ip1 = {

"device_type":"hp_procurve",

"ip": "192.168.48.2",

"username":"Hendrik",

"password":"test"

}

print ("Wait please")

print("sh tech all will be printed in file" )

# output in Datei sh_tech.txt

sys.stdout = open('sh_tech_192_168_48_2.txt', 'w')

sh_tech = net_connect.send_command("sh tech all")

print (sh_tech)

sys.stdout.close()

It would be better if I can enter the network for example 192.168.48.0/24
and for every switch it will be created a seperate textfile.



No comments:

Post a Comment