-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpara.py
55 lines (45 loc) · 1.19 KB
/
para.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
#! /usr/bin/python
import paramiko
import time
username = "your_username"
password = "your_password"
enable_pw = "enable_password"
devices = {
"192.168.14.2": "ASA",
"192.168.14.1": "IOS"
}
commands = ["sh ver", "sh int ip br", "sh vlan br"]
def main():
ssh_conn(devices)
def enable(conn, enable_pw):
conn.send("enable\r")
time.sleep(1)
conn.send(enable_pw + "\r")
time.sleep(1)
def ssh_conn(devices):
for device, type in devices.iteritems():
output = []
conn_pre = paramiko.SSHClient()
conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
conn_pre.connect(device, username=username, password=password)
time.sleep(1)
conn = conn_pre.invoke_shell()
time.sleep(1)
if ">" in conn.recv(100000):
enable(conn, enable_pw)
time.sleep(1)
if type.lower() == "asa":
conn.send("term page 0\r")
time.sleep(1)
if type.lower() == "ios" or type.lower() == "nxos":
conn.send("term len 0\r")
time.sleep(1)
for command in commands:
conn.send(command + "\r")
time.sleep(1)
output.append(conn.recv(100000))
with open(device + ".out", "w+") as out_file:
out_file.writelines(output)
print("{}.out created".format(device))
if __name__ == "__main__":
main()