-
Notifications
You must be signed in to change notification settings - Fork 2
/
backup_router.py
53 lines (40 loc) · 1.37 KB
/
backup_router.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
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
"""
Creation Data ..: 05/29/2013
Developer ......: Waldirio M. Pinheiro <[email protected]>
Luiz Cahue <[email protected]>
Description ....: Connect to cisco equipment to collect config and generate a backup file.
Changelog ......:
"""
import telnetlib
import datetime
def openList():
file = open('list_router.txt','r')
for b in file:
backupRouter(b)
def backupRouter(server):
print "Backup of Server " + server.rstrip()
# Variables
HOST = server.rstrip()
passLogin = "expasswd" # The External password
passEna = "inpasswd" # The Internal password
tn = telnetlib.Telnet(HOST)
tn.read_until("Password: ")
tn.write(passLogin + "\n")
tn.write("ena\n")
tn.read_until("Password: ")
tn.write(passEna + "\n")
# To define the terminal size equal 0, removing the -- more --
# option in show run
tn.write("term length 0\n")
tn.write("show run \n")
tn.write("exit\n")
# To get the date and add in the name file
actualData=datetime.datetime.now()
aux = actualData.strftime("%m_%d_%Y")
# Generating a file named config.dump_<mm_dd_yyyy>.txt
fileName = "config_" + HOST + ".dump_" + str(aux) + ".txt"
fileRef = open(fileName,'w')
fileRef.write(tn.read_all())
fileRef.close()
openList()