-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsearch_endpoint_by_mac.py
executable file
·42 lines (33 loc) · 1.06 KB
/
search_endpoint_by_mac.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
#!/usr/bin/env python
import re
import sys
from local_helpers import accounts_db, utils_endpoint
if __name__ == "__main__":
if (len(sys.argv) != 2):
sys.exit('\nusage: ./script.py <string>\n')
mac_address = str.strip(re.sub(':|\.', '', sys.argv[1]))
mac_address = mac_address.lower()
if (len(mac_address) > 12):
print 'Invalid MAC Address size'
sys.exit()
else:
'''correct mac address format'''
mac_address = ':'.join(mac_address[i:i+2] for i in range(0, len(mac_address), 2))
'''get credentials from accounts_db'''
creds_read = None
try:
for creds in accounts_db.accounts_pan:
if creds.get('ise_role') == str('secondary'):
creds_read = creds
except Exception, e:
print e
sys.exit()
try:
results = utils_endpoint.search_endpoint_by_mac(creds,mac_address)
except Exception, e:
pass
#print e
#sys.exit()
if results:
for result in results:
print utils_endpoint.json_pretty_print(result)