-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject2.py
More file actions
42 lines (36 loc) · 1.25 KB
/
Project2.py
File metadata and controls
42 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from netmiko import ConnectHandler
from rich import print as r_print
import credentials
devices =[
{
"device_type": "cisco_ios",
"host":credentials.HOST,
"username": credentials.USERNAME,
"password": credentials.PASSWORD,
"port": 22
},
{
"device_type": "cisco_ios",
"host":credentials.HOST,
"username": credentials.USERNAME,
"password": credentials.PASSWORD,
"port": 22
},
]
for device in devices:
try:
r_print(f"Connecting to {device["host"]}....")
net_connect = ConnectHandler(**device)
hostname= net_connect.send_command("show run | include hostname")
version = net_connect.send_command("show version | include version")
interface = net_connect.send_command("show ip interface brief")
with open("network_inventory.txt","a") as file:
file.write(f"\nDevice: {device["host"]}\n")
file.write(f"\n{hostname}\n")
file.write(f"\n{version}\n")
file.write(f"\n{interface}\n")
file.write("-"*100 + "\n")
net_connect.disconnect()
r_print(f"Finished connecting to {device["host"]}...\n")
except Exception as e:
r_print(f"Failed to connect to {device["host"]}.....")