-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHP-SwitchBackup.py
72 lines (68 loc) · 2.32 KB
/
HP-SwitchBackup.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import requests
import os
import colorama
import sys
import time
import datetime
from orionsdk import SwisClient
import getpass
from multiprocessing.dummy import Pool
from netmiko import ConnectHandler
from colorama import Fore, Back, Style
colorama.init()
verify = False
x=39
while x<=240:
#Set progress and show
progress = x/240
progress = progress * 100
print(Fore.GREEN + 'Percent completed:',progress)
print(Fore.WHITE)
#set login information
ipAddress="192.168.1."+str(x)
switch_local = {
'device_type':'hp_procurve',
'ip':ipAddress,
'username':'[username]',
'password':'[password]',
'port':'22'
}
print(ipAddress)
hostname =""
try:
#ping system to see if its up
print("Ping IP to verify connectivity...")
response = os.system("ping -n 1 " + ipAddress)
if response == 1:
print(Fore.RED+"Unable to ping to:",ipAddress)
else:
print(Fore.GREEN+"Successful ping to:",ipAddress)
print(Fore.WHITE)
switch_connection = ConnectHandler(**switch_local)
print("Connected to " + ipAddress)
#Save config now in case of any previous changes
switch_connection.send_command('write memory')
local_auth_connection = ConnectHandler(**switch_local)
output = switch_connection.send_command("show run")
hostname = local_auth_connection.find_prompt()
print(hostname)
#Create file for saving the config to
print("Creating file...")
fileName = open("%s.txt" % hostname,"w")
print("Writing config to file...")
#Write output to file
fileName.write(output)
print("Closing file...")
fileName.close()
#Close connection from switch
local_auth_connection.disconnect()
switch_connection.disconnect()
switch_connection.disconnect()
print("Disconnecting from " + ipAddress)
print ("-----------------------------------")
hostname=""
except:
print(Fore.RED + "!!!!!!!ERROR!!!!!!!")
print("Problem with:",hostname," - ",ipAddress)
print ("-----------------------------------")
x=x+1