-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject3.py
More file actions
34 lines (27 loc) · 986 Bytes
/
Copy pathProject3.py
File metadata and controls
34 lines (27 loc) · 986 Bytes
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
from netmiko import ConnectHandler
import datetime
import credentials
class deviceOutput:
'''This Class outlines the data that gets taken from the Network Device and saved into an output file'''
def __init__(self, string):
self.string = string
def createNewFile(self):
'''This Function checks the date and time and appends this to the filename during creation'''
filename = f"output_{datetime.date.today()}.txt"
with open(filename, "a") as f:
f.write(self.string)
networkDevice1 = {
"device_type": "cisco_ios",
"host": credentials.HOST,
"username": credentials.USERNAME,
"password": credentials.PASSWORD,
}
# Show command that we execute
command = "show ip route"
net_connect = ConnectHandler(**networkDevice1)
output = net_connect.send_command(command)
# Create instance of the class
outputFromDevice = deviceOutput(output)
print("Saving Output now...")
outputFromDevice.createNewFile()
print("Complete.")