Skip to content

Instantly share code, notes, and snippets.

@tzermias
Forked from danmilleruk/senderbase.php
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzermias/3f9f42e1a66474d82148 to your computer and use it in GitHub Desktop.
Save tzermias/3f9f42e1a66474d82148 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
# Senderbase Monitoring Plugin for Nagios
# Dan Miller <dm@sub6.com>
error_reporting(E_ERROR | E_PARSE);
# Function to swap the octets of an IP...
# ..address around in to ARPA formatting.
function ipToArpa($address) {
$raw = explode(".", $address);
return "{$raw[3]}.{$raw[2]}.{$raw[1]}.{$raw[0]}";
}
$ip = $argv[1]; # IP address argument
$ar = ipToArpa($ip); # Convert the IP to ARPA formatting
$server = "rf.senderbase.org"; # What we append to the end of our query
# Let's check whether the IP address is valid.
$check = filter_var($ip, FILTER_VALIDATE_IP);
if(!$check) {
die("[ERROR] No IP address given\n");
}
$result = dns_get_record("{$ar}.{$server}", DNS_TXT); # Init query.
$reputation = $result[0]['entries'][0]; # Reputation score
# If the array returns nothing, just die.
if($reputation == "") {
echo "[ERROR] No results given\n";
exit(0); # Exit with an OK for now, as not to clog up nagios.
}
echo "REPUTATION STATUS: ";
# Check against the results we've received.
if($reputation > 0) {
echo "GOOD ({$reputation})\n";
exit(0); # OK
} elseif($reputation >= -0.1) {
echo "NEUTRAL ({$reputation})\n";
exit(0); # OK
} elseif($reputation < 0) {
echo "POOR ({$reputation})\n";
exit(1); #WARNING
} else {
echo "UNKNOWN ({$reputation})\n";
exit(3); # UNKNOWN
# We should never get to this state, just in case we do...
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment