Forum Moderators: coopster
I want to be notified by email when someone visits that is on the blacklist.
Here is the script. I am new to writing my own PHP code, so most of it was pieced together... bound to be mistakes.
##Start##
<?
function exists_in_rbl() {
$rbls = array('http.dnsbl.example.net', 'misc.dnsbl.example.net');
$remote = $_SERVER['REMOTE_ADDR'];
if (preg_match(”/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/”,
$remote, $matches)) {
foreach ($rbls as $rbl) {
$rblhost = $matches[4] . “.” . $matches[3] . “.” .
$matches[2] . “.” . $matches[1] . “.” . $rbl;
$resolved = gethostbyname($rblhost);
if ($resolved != $rblhost) {
return true;
}
}
}
return false;
$to = "webmaster@example.com";
$subject = "Blacklist Hit";
$body = "SPAM,\n\n?HIT";
if (mail($to, $subject, $body)) {
}
}?>
##End##
I am not sure how to initiate the email when a match "true" is made. Can anyone help me complete this? I am using a php file with an "include one" on my index.php file.
Is this correct? :)
[edited by: eelixduppy at 5:53 am (utc) on Dec. 18, 2008]
[edit reason] exemplified [/edit]
You Made some msitake in this function:
If $remote = '202.195.23.45' then the value of the variable rblhost will be (93.246.74.202.http.dnsbl.example.net) or (93.246.74.202.misc.dnsbl.example.net) so $rblhost will not be a correct parameter for the function gethostbyname()
You Can use the below one...
function exists_in_rbl(){
$rbls = array('mahabub.info','mahabub.me','mahabub.org','mahabub.biz');
$remote = $_SERVER['REMOTE_ADDR'];
if(preg_match("/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/",$remote, $matches)){
foreach ($rbls as $rbl){
$resolved = gethostbyname($rbl);
if($resolved!=$remote)
return true;
unset($resolved);
}
}
return false;
// Email Function Goes Here
}
Thanks
Mahabub