8
8
A Python 3 script to pull of the enabled BSSID from an Organization.
9
9
10
10
Required Python modules:
11
- meraki
11
+ meraki 1.48.0 or higher
12
12
13
13
Usage:
14
14
bssid.py
15
15
16
- If you have only one Organization, it will find all BSSID in each Network
17
- and create a csv for each in Documents/BSSID/Organization
16
+ If you have only one Organization, it will find all BSSID
17
+ and create a csv for each network in Documents/BSSID/Organization
18
18
19
19
If you have multiple Organizations, it will ask you which org to run against
20
20
30
30
31
31
32
32
def base_folder ():
33
+ '''
34
+ Check if the root folder exists and create it if not
35
+ '''
33
36
if not Path .is_dir (loc ):
34
37
Path .mkdir (loc )
35
38
36
39
37
40
def get_orgs ():
41
+ '''
42
+ get a list of organizations the user has access to and return that dict
43
+ '''
38
44
orgs = dashboard .organizations .getOrganizations ()
39
45
org_dict = {}
40
46
for i in orgs :
@@ -43,10 +49,17 @@ def get_orgs():
43
49
44
50
45
51
def find_org (org_dict ):
52
+ '''
53
+ If only one organizaiton exists, use that org_id
54
+ '''
46
55
if len (org_dict ) == 1 :
47
56
org_id = org_dict [0 ]['id' ]
48
57
org_name = org_dict [0 ]['name' ]
49
58
else :
59
+ '''
60
+ If there are multiple organizations, ask the use which one to use
61
+ then store that information to be used
62
+ '''
50
63
org_id = input (
51
64
f"Please type the number of the Organization you want to find "
52
65
f"the bssid in{ json .dumps (org_dict , indent = 4 )} " "\n " )
@@ -55,6 +68,9 @@ def find_org(org_dict):
55
68
56
69
57
70
def org_folder (org_name ):
71
+ '''
72
+ check if the organizaiton folder exists, create if not
73
+ '''
58
74
loc2 = Path .joinpath (loc , org_name )
59
75
if not Path .is_dir (loc2 ):
60
76
Path .mkdir (loc2 )
@@ -63,6 +79,7 @@ def org_folder(org_name):
63
79
def get_networks (org_id ):
64
80
net_list = dashboard .organizations .getOrganizationNetworks (
65
81
org_id , total_pages = 'all' )
82
+ print (net_list )
66
83
return net_list
67
84
68
85
@@ -71,60 +88,35 @@ def find_networks(net_list):
71
88
for i in net_list :
72
89
if 'wireless' in i ['productTypes' ]:
73
90
net_ids [i ['id' ]] = i ['name' ]
74
- net_name = i ['name' ]
75
- return net_ids , net_name
91
+ return net_ids
76
92
77
93
78
- def find_ap (net_ids ):
79
- ap_dict = {}
80
- for k , v in net_ids .items ():
81
- name = v
82
- lst = []
83
- devices = dashboard .networks .getNetworkDevices (k )
84
- for i in devices :
85
- model = i ['model' ][:2 ]
86
- if model == 'MR' or model == 'CW' :
87
- dic = {}
88
- if i .get ('name' ) is None :
89
- dic .update (name = i ['mac' ], serial = i ['serial' ])
90
- else :
91
- dic .update (name = i ['name' ], serial = i ['serial' ])
92
- lst .append (dic )
93
- ap_dict [name ] = lst
94
- return ap_dict
95
-
96
-
97
- def get_bssid (ap_dict , net_ids ):
98
- bssid_dict = {}
99
- for k , v in net_ids .items ():
100
- name = v
101
- lst = []
102
- for data in ap_dict [name ]:
103
- ap = data ['serial' ]
104
- response = dashboard .wireless .getDeviceWirelessStatus (ap )
105
- for value in response ['basicServiceSets' ]:
106
- info_dict = {}
107
- good = value ['enabled' ]
108
- if good is True :
109
- info_dict ['name' ] = data ['name' ]
110
- info_dict ['ssidName' ] = value ['ssidName' ]
111
- info_dict ['band' ] = value ['band' ]
112
- info_dict ['bssid' ] = value ['bssid' ]
113
- lst .append (info_dict )
114
- bssid_dict [name ] = lst
94
+ def get_bssid (org_id , net_ids ):
95
+ '''
96
+ dump the BSSID list for the organization
97
+ '''
98
+ bssid_dict = dashboard .wireless .getOrganizationWirelessSsidsStatusesByDevice \
99
+ (org_id , total_pages = 'all' )
115
100
return bssid_dict
116
101
117
102
118
103
def file_writer (bssid_dict , net_ids , org_name ):
104
+ print (f'writing BSSID to file' )
119
105
for k , v in net_ids .items ():
120
- network = v
121
- file = f'{ loc } /{ org_name } /{ network } .csv'
106
+ net_name = v
107
+ file = f'{ loc } /{ org_name } /{ net_name } .csv'
122
108
with open (file , mode = 'w' ) as f :
123
- f .write (f"AP Name , SSID Name , Frequency , BSSID" + "\n " )
124
- for data in bssid_dict [network ]:
125
- f .write (f"{ data ['name' ]} , { data ['ssidName' ]} , "
126
- f"{ data ['band' ]} , { data ['bssid' ]} " + "\n " )
127
- print (f'Your file { network } .csv has been created in { loc } / { org_name } ' )
109
+ f .write (f"AP Name , SSID Name , Frequency , BSSID, AP Serial" + "\n " )
110
+ for ap in bssid_dict ['items' ]:
111
+ network = ap ['network' ]['name' ]
112
+ if net_name == network :
113
+ for bss in ap ['basicServiceSets' ]:
114
+ f .write (f"{ ap ['name' ]} , "
115
+ f"{ bss ['ssid' ]['name' ]} , "
116
+ f"{ bss ['radio' ]['band' ]} GHz, "
117
+ f"{ bss ['bssid' ]} , "
118
+ f"{ ap ['serial' ]} " + "\n " )
119
+ print (f'Your file { net_name } .csv has been created in { loc } /{ org_name } ' )
128
120
129
121
130
122
def main ():
@@ -133,10 +125,8 @@ def main():
133
125
org_id , org_name = find_org (org_dict )
134
126
org_folder (org_name )
135
127
net_list = get_networks (org_id )
136
- net_ids , net_name = find_networks (net_list )
137
- ap_dict = find_ap (net_ids )
138
- bssid_dict = get_bssid (ap_dict , net_ids )
139
- print (f'writing BSSID to file' )
128
+ net_ids = find_networks (net_list )
129
+ bssid_dict = get_bssid (org_id , net_ids )
140
130
file_writer (bssid_dict , net_ids , org_name )
141
131
142
132
0 commit comments