You are herehttp:BL Code

http:BL Code


demo_page.php

<?php
@$httpbl_action = $_REQUEST['action'];
@
$httpbl_ipaddr = $_REQUEST['httpbl_ipaddr'];


switch (
$httpbl_action){
    default:
       
?>
<h2>Check the Status of an IP Address on http:BL</h2><br /><br />
<form id="httbl" name="httbl" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <p>IP Address to Check
    <input name="httpbl_ipaddr" type="text" id="httpbl_ipaddr" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" />
    <input type="hidden" name="action" value="check" />
</p>
  <p>Check It!
    <input type="submit" name="Submit" value="Submit" />
</p>
</form>
<p>http:BL data is provided by <a href="http://projecthoneypot.org" target="_blank">Project Honey Pot</a>.  This script by <a href="http://huber-home.org">Beau Huber</a>. The code for this script is comming soon!</p>
<?php
   
break;
   
    case
'check':
        echo
'<h2>Results of the http:BL Check</h2><br /><br />';
        include_once(
"functions.php");
       
        if (
blreason(checkhttpbl($httpbl_ipaddr),true)){
    echo
"<font color=\"green\"><strong>Pass!</strong></font><br /><br />
    IP Address:
$httpbl_ipaddr (<a href=\"http://www.projecthoneypot.org/search_ip.php?ip=$httpbl_ipaddr\" target=\"_blank\">Project Honey Pot</a>)(<a href=\"http://www.dnsstuff.com/tools/whois.ch?ip=$httpbl_ipaddr\" target=\"_blank\">DNS Stuff</a>) <br />
    Hostname: "
.gethostbyaddr($httpbl_ipaddr)."";
   
}else {
    echo
"<font color=\"red\"><strong>Fail!</strong></font><br /><br />
    IP Address:
$httpbl_ipaddr (<a href=\"http://www.projecthoneypot.org/search_ip.php?ip=$httpbl_ipaddr\" target=\"_blank\">Project Honey Pot</a>)(<a href=\"http://www.dnsstuff.com/tools/whois.ch?ip=$httpbl_ipaddr\" target=\"_blank\">DNS Stuff</a>) <br />
    Hostname: "
.gethostbyaddr($httpbl_ipaddr)."";
}
echo
'<br /><br /><a href="http://huber-home.org/page/http_bl">Check Anther IP Address</a><br />';
echo
'<p>http:BL data is provided by <a href="http://projecthoneypot.org" target="_blank">Project Honey Pot</a>.  This script by <a href="http://huber-home.org">Beau Huber</a>.</p>';
       
    break;
}
?>

functions.php
<?php
function checkhttpbl($ip){
   
   
/* We need to explode the ip so we can flip it around */
   
$ips = explode(".",$ip);
   
$ipn = $ips['3'] . "." . $ips['2'] . "." . $ips['1'] . "." . $ips['0'];

   
/* Now check it aginst the BL */
   
$hostname = "_you_api_key_here_.$ipn.dnsbl.httpbl.org";
   
$ipres = gethostbyname($hostname);

    if (!
check_wl($ip)){
    if (
is_ipaddress($ipres)){
            return 
$ipres;
        }else {
            return
"127.8.0.0";
        }}else {
            return
"127.-1.0.0";
        }
}

function
check_wl($ip){
   
   
$exip = explode(".",$ip);
   
$neip1 = $exip['0'] . "." . $exip['1'] . "." . $exip['2'];
   
$neip2 = $exip['0'] . "." . $exip['1'] . "." . $exip['2'] . "." . $exip['3'];
       
    include(
"ips.php");
    if (
in_array($neip1,$whitelisted_ips) || in_array($neip2,$whitelisted_ips)){
        return
true;
    }else {
        return
false;
    }
}


function
blreason($blip,$show_debug=false){
   
/* Will return false if we think its bad */
    /* Will retrun true if we think its good */
   
   
$ips = explode(".",$blip);
   
$count = '';
   
   
/* This should always be 127 */
   
if ($ips['0'] == "127"){
       
/* We don't need to do anything with this one */
   
}

   
/* The days the IP was last seen doing somthing bad */
   
if ($ips['1'] == "-1"){
       
$count = $count-100;
    }elseif (
$ips['1'] >= "7"){
       
$count = $count-1;
    }elseif (
$ips['1'] <= "6"){
       
$count = $count+1;
    }else {
/* Fail Safe */
       
$count = $count+0;
    }
   
   
/* This represents a threat score for IP, from 0 - 255 */
   
if ($ips['2'] <= "10"){
       
$count = $count-1;
    }elseif (
$ips['2'] >= "11"){
       
$count = $count+$ips['2'];
    }else {
/* Fail Safe */
       
$count = $count+0;
    }
       
   
/* This represents the type of visitor, 0-Search Engine, 1-Suspicious, 2-Harvester, 4-Comment Spammer */
   
if ($ips['3'] = "0"){
       
$count = $count-1;
    }elseif (
$ips['3'] = "1"){
       
$count = $count+1;
    }elseif (
$ips['3'] = "2"){
       
$count = $count+2;
    }elseif (
$ips['3'] = "3"){
       
$count = $count+3;
    }elseif (
$ips['3'] = "4"){
       
$count = $count+4;
    }elseif (
$ips['3'] = "5"){
       
$count = $count+5;
    }elseif (
$ips['3'] = "6"){
       
$count = $count+6;
    }elseif (
$ips['3'] = "7"){
       
$count = $count+7;
    }else {
/* Fail Safe */
       
$count = $count+0;
    }
   
    if (
$show_debug == true){
    echo
"Score: $count<br />";
    echo
"Black List Result: $blip<br />";}
   
    if (
$count <= 2){
        return
true;
    }elseif (
$count >= 3){
        return
false;
    }else {
        return
true;
    }
}





//    ************************************************************
//    Dotted quad IPAddress within valid range?
//      true or false
//    Checks format, leading zeros, and values > 255
//    Does not check for reserved or unroutable IPs.
//      From: thewebmasters.net/php/Validator.phtml

   
function is_ipaddress ($IP = "")
    {

        if(empty(
$IP))
        {
           
$this->ERROR = "is_ipaddress: No IP address submitted";
            return
false;
        }
       
//    123456789012345
        //    xxx.xxx.xxx.xxx

       
$len = strlen($IP);
        if(
$len > 15 )
        {
           
$this->ERROR = "is_ipaddress: too long [$IP][$len]";
            return
false;
        }

       
$Bad = eregi_replace("([0-9\.]+)","",$IP);

        if(!empty(
$Bad))
        {
           
$this->ERROR = "is_ipaddress: Bad data in IP address [$Bad]";
            return
false;
        }
       
$chunks = explode(".",$IP);
       
$count = count($chunks);

        if (
$count != 4)
        {
           
$this->ERROR = "is_ipaddress: not a dotted quad [$IP]";
            return
false;
        }

        while ( list (
$key,$val) = each ($chunks) )
        {
            if(
ereg("^0",$val))
            {
               
$this->ERROR = "is_ipaddress: Invalid IP segment [$val]";
                return
false;
            }
           
$Num = $val;
           
settype($Num,"integer");
            if(
$Num > 255)
            {
               
$this->ERROR = "is_ipaddress: Segment out of range [$Num]";
                return
false;
            }

        }

        return
true;

    }   
// end is_ipaddress
?>

ips.php
<?php
         
$whitelisted_ips
= array("127.0.0.1",
                        
"10.10.1",
                        
"71.39.63.73"
                        
);
?>

Tags