How to execute a request via php spamhaus blacklist

Attempt to query spamhaus.org

for blacklist ip. Example: 69.35.160.59

If I go to https://www.spamhaus.org/lookup/

and type it, it appears blacklisted with 112.198.83.17

, however the following code returns an empty array.

I print the url and it appears to be formatted correctly in the reverse ip 17.83.198.112.zen.spamhaus.org

.

Any ideas?

<?php

    $ip = "112.198.83.17";
    $blacklist = "zen.spamhaus.org";
    $url = implode(".", array_reverse(explode(".", $ip))) . ".". $blacklist;
    echo "$url<br>";
    $record = dns_get_record($url);
    print_r ($record);

?>

      

+3


source to share


3 answers


You are doing the right thing. See here for result codes http://www.spamhaus.org/faq/section/DNSBL%20Usage#366

Here is my output for ip 69.35.160.59



Array (
    [0] => Array
        (
            [host] => 59.160.35.69.zen.spamhaus.org
            [type] => A
            [ip] => 127.0.0.4
            [class] => IN
            [ttl] => 900
        )

[1] => Array
    (
        [host] => 59.160.35.69.zen.spamhaus.org
        [type] => TXT
        [txt] => http://www.spamhaus.org/query/bl?ip=69.35.160.59
        [entries] => Array
            (
                [0] => http://www.spamhaus.org/query/bl?ip=69.35.160.59
            )

        [class] => IN
        [ttl] => 900
    )

      

+2


source


Your code is correct. Just make sure you are not using publicly available dns converters like 8.8.8.8 and 8.8.4.4, because the code won't work if you do. You can check which resolvers you are using by looking at the / etc / resolv.conf file



+2


source


I've created a simple function that returns true if specified in SpamHaus. Any incoming IP addresses are checked and allowed or blocked:

function callSpamhaus($UserIP) {
    // NON-INFECTED IP FOR TESTING
    // 192.99.150.120
    // INFECTED IP FOR TESTING
    // 216.145.14.142
    $blacklist = "zen.spamhaus.org";
    $url = implode(".", array_reverse(explode(".", $UserIP))) . ".". $blacklist;
    $record = dns_get_record($url);
    if (is_array($record) && !empty($record)) :
        return TRUE;
    endif;
}

      

Every time you access a site that triggers this function, a conditional usage is performed using whatever method you choose to get the IP address and create a variable for it:

$SpamHaus = callSpamhaus($IPAddress);
if ($SpamHaus === TRUE) :
     Redirect("/administration/accessblocked.php");
endif;

      

0


source







All Articles