forked from adiroata/network_automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup_telnet.py
44 lines (34 loc) · 968 Bytes
/
backup_telnet.py
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
42
#!/usr/bin/env python
import getpass
import sys
import telnetlib
import time
#import os
#import itertools
#import gzip
#import csv
# Introduceti user si pass
user = raw_input("Introduceti username: ")
password = getpass.getpass()
timestamp = time.strftime("%d" + "-" + "%m" + "-" + "%Y")
loops = open("loopbacks")
for line in loops:
try:
print "Se acceseaza : " + (line)
HOST=line.strip()
tn=telnetlib.Telnet(HOST)
tn.read_until("Username: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("terminal length 0\n")
tn.write("show run\n")
tn.write("exit\n")
readoutput=tn.read_until("exit", 5)
saveoutput=open("config_host_" + HOST + "_" + timestamp, "w")
saveoutput.write(readoutput)
saveoutput.close
# print readoutput
except:
print("Hostul " + str(HOST) + " e down.")