-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveConfigOutputTelnet.py
More file actions
34 lines (27 loc) · 896 Bytes
/
saveConfigOutputTelnet.py
File metadata and controls
34 lines (27 loc) · 896 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
#! /bin/bash/python3
# Telnetexample connecting to a switch saving the 'show run'
import getpass
import telnetlib
HOST = input("Enter the IP Address of Device: ")
user = input("Enter your cisco username: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
tn.write(b"terminal len 0\n")
tn.write(b"show running-config\n")
tn.write(b"show ip interface brief\n")
tn.write(b"show vlan\n")
tn.write(b"exit\n")
tn.write(b"exit\n")
readoutput = tn.read_all()
saveoutput = open("Device " + HOST + ".txt", "w")
saveoutput.write(readoutput.decode('ascii'))
saveoutput.close()
print(tn.read_all().decode('ascii'))
print("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*")
print("<-- Script has completed --->")
print("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*")