-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathreport_auths_by_country.py
More file actions
executable file
·43 lines (38 loc) · 1.15 KB
/
report_auths_by_country.py
File metadata and controls
executable file
·43 lines (38 loc) · 1.15 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
#!/usr/bin/env python
from __future__ import print_function
from __future__ import absolute_import
import csv
import sys
import duo_client
import json
from six.moves import input
argv_iter = iter(sys.argv[1:])
def get_next_arg(prompt):
try:
return next(argv_iter)
except StopIteration:
return input(prompt)
# Configuration and information about objects to create.
admin_api = duo_client.Admin(
ikey=get_next_arg('Admin API integration key ("DI..."): '),
skey=get_next_arg('integration secret key: '),
host=get_next_arg('API hostname ("api-....duosecurity.com"): '),
)
# Retrieve log info from API:
logs = admin_api.get_authentication_log()
# Count authentications by country:
counts = dict()
for log in logs:
country = log['location']['country']
if country != '':
counts[country] = counts.get(country, 0) + 1
# Print CSV of country, auth count:
auths_descending = sorted(counts.items(), reverse=True)
reporter = csv.writer(sys.stdout)
print("[+] Report of auth counts by country:")
reporter.writerow(('Country', 'Auth Count'))
for row in auths_descending:
reporter.writerow([
row[0],
row[1],
])