/
wifi031516.py
145 lines (112 loc) · 4.52 KB
/
wifi031516.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#! /usr/bin/python
# This work is licensed under the GNU General Public License v3.0
#
# Dependencies pexpect (Python Expect).
import pexpect
import pickle
from time import sleep
# Please place your seed device in the to_crawl list.
# modify the to_crawl list. i.e. to_crawl = ['yourrouter1']
user = raw_input('Username? ')
passwd = raw_input('Password? ')
globalswitch_ip = raw_input('Wireless Controller? ')
def apdump(switch_ip,switch_un,switch_pw):
# cdpout = [switch_ip]
child = pexpect.spawn('telnet %s' % (switch_ip))
child.logfile = open("./mylog", "w")
loginresult = child.expect(['[Uu]ser'])
child.timeout = 10
if loginresult == 0:
child.sendline(switch_un)
child.expect('[Pp]assword:')
child.sendline(switch_pw)
child.expect('>')
child.sendline('config paging disable')
child.expect('>')
child.sendline('show ap summary')
child.expect('>')
child.logfile.close()
else:
exit
routerFile = open('./mylog', 'r')
datalist = routerFile.read()
routerFile.close()
return datalist
logstring = apdump(globalswitch_ip,user,passwd)
loglist = logstring.split()
aplist = []
for count,i in enumerate(loglist):
if 'AIR-' in i:
aplist.append(loglist[count - 2])
child = pexpect.spawn('telnet %s' % (globalswitch_ip))
# child.logfile = open("./aplog", "w")
child.expect(['[Uu]ser'])
child.sendline(user)
child.expect('[Pp]assword:')
child.sendline(passwd)
child.expect('>')
child.timeout = 10
aplargelist = []
while aplist:
child.logfile = open("./aplog", "w")
aptarget = aplist.pop()
child.sendline('config paging disable')
child.expect('>')
child.sendline('show ap config general %s' % (aptarget))
child.expect('>')
child.sendline('show ap cdp neighbors ap-name %s' % (aptarget))
child.expect('>')
child.logfile.close()
APFile = open('./aplog', 'r')
apdatalist = APFile.read()
APFile.close()
apdatalistSPLIT = apdatalist.split()
apoutlist = []
apout = open('./apout.txt', 'w')
for count,i in enumerate(apdatalistSPLIT):
if ('Cisco' in i and 'AP' in apdatalistSPLIT[count + 1] and 'Name' in apdatalistSPLIT[count + 2]):
apoutlist.append(apdatalistSPLIT[count + 3])
if ('assigned' in i and 'IP' in apdatalistSPLIT[count + 1] and 'Address' in apdatalistSPLIT[count + 2]):
apoutlist.append('STATIC')
apoutlist.append(apdatalistSPLIT[count + 3])
if ('DHCP' in i and 'IP' in apdatalistSPLIT[count + 1] and 'Address' in apdatalistSPLIT[count + 2]):
apoutlist.append('DHCP')
apoutlist.append(apdatalistSPLIT[count + 3])
if ('MAC' in i and 'Address' in apdatalistSPLIT[count + 1]):
apoutlist.append('MAC')
apoutlist.append(apdatalistSPLIT[count + 2])
if ('Cisco' in i and 'AP' in apdatalistSPLIT[count + 1] and 'Group' in apdatalistSPLIT[count + 2] and 'Name' in apdatalistSPLIT[count + 3]):
apoutlist.append('AP GROUP')
apoutlist.append(apdatalistSPLIT[count + 4])
if ('Primary' in i and 'Cisco' in apdatalistSPLIT[count + 1] and 'Switch' in apdatalistSPLIT[count + 2] and 'Name' in apdatalistSPLIT[count + 3]):
apoutlist.append('PRIMARY')
apoutlist.append(apdatalistSPLIT[count + 4])
if ('Secondary' in i and 'Cisco' in apdatalistSPLIT[count + 1] and 'Switch' in apdatalistSPLIT[count + 2] and 'Name' in apdatalistSPLIT[count + 3]):
apoutlist.append('SECONDARY')
apoutlist.append(apdatalistSPLIT[count + 4])
if ('Tertiary' in i and 'Cisco' in apdatalistSPLIT[count + 1] and 'Switch' in apdatalistSPLIT[count + 2] and 'Name' in apdatalistSPLIT[count + 3]):
apoutlist.append('TERTIARY')
apoutlist.append(apdatalistSPLIT[count + 4])
if ('Neighbor' in i and 'Name' in apdatalistSPLIT[count + 1]):
apoutlist.append('CONNECTED TO')
try:
apoutlist.append(apdatalistSPLIT[count + 10])
apoutlist.append(apdatalistSPLIT[count + 11])
except IndexError:
apoutlist.append('ERROR')
apoutlist.append('ERROR')
# for item in apoutlist:
# apout.write(item)
# apout.write(",")
# apout.write("\n")
# apout.write(apoutlist)
# pickle.dump(apoutlist, apout)
# apout.write("\n".join(apoutlist))
aplargelist.append(apoutlist)
# print apoutlist
print aplargelist
for item in aplargelist:
print >> apout, item
# for count,i in enumerate(apdatalistSPLIT):
# print count,i
# sleep(1)