-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreauth_session_by_ip.py
More file actions
executable file
·67 lines (57 loc) · 2.35 KB
/
reauth_session_by_ip.py
File metadata and controls
executable file
·67 lines (57 loc) · 2.35 KB
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
#!/usr/bin/env python
import sys
import random
import json
import xml.etree.ElementTree as et
from local_helpers import accounts_db, mnt_sessions
if __name__ == "__main__":
if (len(sys.argv) != 2):
sys.exit('\nusage: ./script.py <ip_address>\n')
ip_address = str.strip(sys.argv[1])
ip_address = ip_address.lower()
'''get credentials from accounts_db'''
try:
creds = random.choice(accounts_db.accounts_mnt)
except Exception, e:
print e
sys.exit()
endpoint_session = None
root = None
try:
results = mnt_sessions.get_session_by_ip(creds,ip_address)
'''returns xml object'''
if results:
root = et.fromstring(results)
if len(root) > 0:
s_token = None
s_param = None
for s_param in root.iter('sessionParameters'):
'''construct json session object to submit'''
s_token = {
"endpoint_mac" : str(s_param.find('calling_station_id').text),
"endpoint_ip" : str(s_param.find('framed_ip_address').text),
"psn_server" : str(s_param.find('acs_server').text),
"switch_ip" : str(s_param.find('nas_ip_address').text),
"auth_timestamp" : str(s_param.find('auth_acs_timestamp').text)
}
reauth_results = None
if s_token:
reauth_results = mnt_sessions.reauth_session(creds,s_token)
r_root = None
r_root = et.fromstring(reauth_results)
if len(r_root) > 0:
for coa in r_root.iter('remoteCoA'):
if str(coa.find('results').text == 'true'):
'''append to dictionary the results'''
s_token['session_terminated'] = True
print mnt_sessions.json_pretty_print(s_token)
else:
print mnt_sessions.json_pretty_print(
{
"results" : str("no-sessions-found-for-ip"),
"endpoint_ip" : str(ip_address)
})
except Exception as e:
error = e
print error
pass