Skip to content

Commit

Permalink
Merge pull request #18 from hmoffatt/master
Browse files Browse the repository at this point in the history
Add IPv6 support
  • Loading branch information
egeland committed Nov 2, 2017
2 parents 65c10e2 + a6b8286 commit 07edae0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -14,14 +14,16 @@ You can run the plugin using either a **hostname** (which will be resolved to an

./check_rbl.py -w <WARN level> -c <CRIT level> -h <hostname>
./check_rbl.py -w <WARN level> -c <CRIT level> -a <ipv4 address>
./check_rbl.py -w <WARN level> -c <CRIT level> -a <ipv6 address>

For example, to test whether hostname `mail.google.com` is listed on any known blacklist, with a **Warning** level of 1 blacklist and a **Critical** level of 3 blacklists, do:

./check_rbl.py -w 1 -c 3 -h mail.google.com

To test the plugin, check `127.0.0.2` which should always come back as "listed" on every known blacklist. For example:
To test the plugin, check `127.0.0.2` or `::FFFF:7F00:2` which should always come back as "listed" on every known blacklist. For example:

./check_rbl.py -w 1 -c 3 -a 127.0.0.2
./check_rbl.py -w 1 -c 3 -a ::FFFF:7F00:2

# Known Blacklists
A list of known blacklists included in the `check_rbl.py` script is located on this Wiki page:
Expand Down
15 changes: 11 additions & 4 deletions check_rbl.py
Expand Up @@ -32,6 +32,7 @@
import string
import Queue
import threading
import ipaddress

# Python version check
rv = (2, 6)
Expand Down Expand Up @@ -177,7 +178,7 @@ def run(self):
def usage(argv0):
print "%s -w <WARN level> -c <CRIT level> -h <hostname>" % argv0
print " or"
print "%s -w <WARN level> -c <CRIT level> -a <ipv4 address>" % argv0
print "%s -w <WARN level> -c <CRIT level> -a <ip address>" % argv0


def main(argv, environ):
Expand Down Expand Up @@ -215,9 +216,15 @@ def main(argv, environ):
except:
print "ERROR: Host '%s' not found - maybe try a FQDN?" % host
sys.exit(status['UNKNOWN'])
addr_parts = string.split(addr, '.')
addr_parts.reverse()
check_name = string.join(addr_parts, '.')

ip = ipaddress.ip_address(unicode(addr))
if (ip.version == 6):
addr_exploded = ipaddress.ip_address(unicode(addr)).exploded
check_name = string.join([c for c in addr_exploded if c != ':'], '.')[::-1]
else:
addr_parts = string.split(addr, '.')
addr_parts.reverse()
check_name = string.join(addr_parts, '.')
# Make host and addr the same thing to simplify output functions below
host = addr

Expand Down

0 comments on commit 07edae0

Please sign in to comment.