-
-
Save mars64/b723a82ce751a7ae49022f2e5f7abbd7 to your computer and use it in GitHub Desktop.
SPF dns lookup nagios check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# usage: ./check-spf.py domain.com | |
# | |
# author: [email protected] | |
# | |
# | |
import sys | |
try: | |
import dns.resolver | |
except: | |
print "Need to install dnspython" | |
sys.exit(1) | |
resolves = 0 | |
def doResolve(host): | |
global resolves | |
answers = dns.resolver.query(host, 'TXT') | |
resolves += 1 | |
for rdata in answers: | |
for part in str(rdata).replace("\" \"", "").split(): | |
if "include" in part: | |
doResolve(part.split(":")[1]) | |
elif part in ["a", "mx", "ptr", "exists"]: | |
resolves += 1 | |
answers = dns.resolver.query(str(sys.argv[1]), 'TXT') | |
for rdata in answers: | |
for part in str(rdata).replace("\" \"", "").split(): | |
if "include" in part: | |
doResolve(part.split(":")[1]) | |
elif part in ["a", "mx", "ptr", "exists"]: | |
resolves += 1 | |
if resolves > 10: | |
print "CRITICAL: Above the 10 allowed resolutions for SPF. You are at %i" % resolves | |
sys.exit(2) | |
print "OK: Below the 10 allowed resolutions for SPF. You are at %i" % resolves | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment