[PHP] Controllare se un IP in blacklist

Nel tutorial di oggi vi mostreremo come creare una funzione PHP che controlla se un IP in blacklist o meno.

 
< ?php 
function blacklist($ip){ 
    $listed = true; 
    $dnsbl_lookup = array( 
        "dnsbl-1.uceprotect.net", 
        "dnsbl-2.uceprotect.net", 
        "dnsbl-3.uceprotect.net", 
        "dnsbl.dronebl.org", 
        "dnsbl.sorbs.net", 
        "zen.spamhaus.org" 
    ); // Add your preferred list of DNSBL's 
    $lookups = count($dnsbl_lookup); 
    $total = 0; 
    if($ip){ 
        $reverse_ip = implode(".", array_reverse(explode(".", $ip))); 
        foreach($dnsbl_lookup as $host){ 
            if(checkdnsrr($reverse_ip.".".$host.".", "A")){ 
                $total++; 
            } 
        } 
    } 
    $percent = ($total / $lookups) * 100; 
    if($percent >= 50){ 
        return true; 
    }else{ 
        return false; 
    } 
} 
 
if(blacklist($_SERVER["REMOTE_ADDR"])){ 
    die("Your on the blacklist!"); 
} 
// Continue with page
 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>