-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy patho365chk.py
80 lines (57 loc) · 2.04 KB
/
o365chk.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
import requests
import json
import argparse
def make_requests(target):
params = {
'login': 'username@' + str(target),
'json': '1'
}
url = 'https://login.microsoftonline.com/getuserrealm.srf'
try:
r = requests.get(url, params=params)
r.raise_for_status()
except requests.exceptions.HTTPError as errh:
print("Http Error:", errh)
raise SystemExit(errh)
except requests.exceptions.ConnectionError as errc:
print("Error Connecting:", errc)
raise SystemExit(errc)
except requests.exceptions.Timeout as errt:
print("Timeout Error:", errt)
raise SystemExit(errt)
except requests.exceptions.RequestException as err:
print("Uh-oh: Something Bad Happened", err)
raise SystemExit(err)
r = r.json()
return r
def get_status(response_json):
x = json.dumps(response_json)
x = json.loads(x)
status = x['NameSpaceType']
if status == 'Managed':
print('This domain is Managed')
elif status == 'Federated':
print('This domain is Federated')
elif status == 'Unknown':
print('No O365 service could be identified for this domain, or it was entered incorrectly.')
else:
print('No O365 status could be found, or there was an error')
return x
def convert_indent(indent):
try:
return int(indent)
except ValueError as errv:
print('You need to enter a number')
print(errv)
quit()
def main():
parser = argparse.ArgumentParser(description='Checks to see if an O365 instance is associated with a domain.')
parser.add_argument('-d', '--domain', help='Specifies the domain to be checked', required=True)
parser.add_argument('-i', '--indent', help='You can change the number of indents', default=4)
args = parser.parse_args()
domain = args.domain
number_of_indent = convert_indent(args.indent)
data = make_requests(domain)
result = get_status(data)
print(json.dumps(result, indent=number_of_indent, sort_keys=True))
main()