-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_functions.py
120 lines (86 loc) · 2.88 KB
/
my_functions.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import dns.resolver, os
from geolite2 import geolite2
from ipwhois import IPWhois
resolver = dns.resolver.Resolver(configure=False)
resolver.nameservers = ['1.1.1.1', '1.0.0.1']
def dig_record(lookup_domain, type):
try:
query = resolver.query(lookup_domain, type)
except:
query = 'null'
answer_list = []
if query == 'null':
answer = 'null'
else:
for item in query:
answer_string = ''
result_string = ''.join([str(item), answer_string])
if type == 'MX':
ttl, mx = result_string.split(' ')
append_tuple = [ttl, mx]
answer_list.append(append_tuple)
else:
answer_list.append(result_string)
answer = answer_list
return answer
def dig_ptr(lookup_domain):
try:
query = resolver.query(lookup_domain, 'A')
except:
query = 'null'
answer_list = []
print(query)
if query == 'null':
answer = 'null'
else:
for item in query:
answer_string = ''
result_string = ''.join([str(item), answer_string])
print(result_string)
#reverse_lookup = dns.reversename.from_address(item)
#answer_list.append(reverse_lookup)
#answer = answer_list
return 'null'
def whois_ip(ip):
reader = geolite2.reader()
answer = reader.get(ip)
geolite2.close()
return answer
def whois_ip_name(ip):
obj = IPWhois(ip)
results = obj.lookup_rdap(depth=1)
return results['network']['name']
def run_dns_checks(lookup_result, result_type):
if result_type is 'MX' and isinstance(lookup_result, list):
#If type is MX then lookup_result is a list,
#so we need to make a loop
problem_detected = ''
remote_provider = ''
active_lowest_mx = ''
active_lowest_mx_provider = ''
lowest_ttl = min([x[0] for x in lookup_result])
for item in lookup_result:
ttl_str = item[0]
mx_str = item[1]
if lowest_ttl == ttl_str:
# Found the lowest TTL, set it to a new variable
active_lowest_mx = mx_str
if 'protection.outlook.com' in mx_str:
remote_provider = True
elif 'google.com' in mx_str:
remote_provider = True
else:
pass
if 'protection.outlook.com' in active_lowest_mx:
remote_provider_active = True
elif 'google.com' in active_lowest_mx:
remote_provider_active = True
else:
remote_provider_active = False
if remote_provider_active == True and remote_provider == True:
problem_detected = False
else:
problem_detected = True
else:
print('Type of lookup_result was not a list.')
return problem_detected