-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_dnscaa
More file actions
88 lines (69 loc) · 2.79 KB
/
check_dnscaa
File metadata and controls
88 lines (69 loc) · 2.79 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
#-------------------------------------------------------------------------------
import os
import sys
import subprocess
import argparse
import mechanize
from bs4 import BeautifulSoup
#-------------------------------------------------------------------------------
_candebug = False
def candebug():
global _candebug
return _candebug
def setcandebug(value):
global _candebug
_candebug = value
def infomsg(msg):
if candebug() == True:
print(msg, flush=True)
def mapstatustoexitcode(status):
if status=="OK":
exitcode = 0
elif status=="WARNING":
exitcode = 1
elif status=="CRITICAL":
exitcode = 2
elif status=="UNKNOWN":
exitcode = 3
else:
exitcode = 4
return exitcode
def exitnagios(status,message):
exitcode = mapstatustoexitcode(status)
print(status+": "+message, flush=True)
sys.exit(exitcode)
#-------------------------------------------------------------------------------
def dodnscaacall(domain):
try:
url = "https://caatest.co.uk/"+domain
br = mechanize.Browser()
br.set_handle_robots(False) # ignore robots file
#br.addheaders = [('User-agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)')]
br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0')]
res = br.open(url)
content = res.read()
if content == None:
exitnagios("CRITICAL","no result from page")
soup = BeautifulSoup(content, "html.parser")
element = soup.find("span",class_="success green")
if element!=None:
exitnagios("OK","the domain has valid CAA records")
else:
exitnagios("CRITICAL","the domain has issues with the CAA records")
except Exception as e:
exitnagios("CRITICAL","unexpected error during the check "+str(e))
#-------------------------------------------------------------------------------
def main(forcedargs=None):
parser = argparse.ArgumentParser()
parser.add_argument('-H', '--host', dest="host", help="Hostname")
parser.add_argument("-®", "--debug", action="store_true", dest="debug", default=False, help="be more verbose")
args = parser.parse_args(forcedargs)
setcandebug(args.debug)
if (args.host == ""):
exitnagios("CRITICAL","specify a host/domain to check")
dodnscaacall(args.host)
#-------------------------------------------------------------------------------
if __name__ == "__main__":
main()
#-------------------------------------------------------------------------------