0

我遇到的问题是,如果我在本地 wampserver 上运行我的这个脚本,那么如果它已经被列入黑名单,但如果我在我的服务器等上运行,它会显示正确的结果...... /usr/bin/php path-to-phpscript。 php 然后它显示这个 ip 在所有不正确的 bls 名称中都被列入黑名单。

<?php

$bls = array("b.barracudacentral.org",
"bl.score.senderscore.com",
"pbl.spamhaus.org",
"sbl.spamhaus.org",
"xbl.spamhaus.org",
"zen.spamhaus.org",
"dbl.spamhaus.org",
"sbl-xbl.spamhaus.org",
);


$ip = '62.213.183.192';

if ( isset($ip)) {

if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) || false === filter_var($ip, FILTER_VALIDATE_URL)) {

    if (false === filter_var($ip, FILTER_VALIDATE_URL  )) { 
        $iptosplit = gethostbyname($ip);
    }
    else {
        $iptosplit = $ip;
    }
    $splitip = explode (".", $iptosplit);
    $iptolookup = "$splitip[3].$splitip[2].$splitip[1].$splitip[0]";
    $counter=1;
    $blList = array();
    foreach ( $bls as $rbl ) {
        //echo "<tr>";
        $rbllookup = $iptolookup.".".$rbl;
        $lookup = gethostbyname($rbllookup);

        if ( $lookup != $rbllookup || $lookup == $ip) {
            $qtxtresult = dns_get_record("$rbllookup", DNS_TXT);
            if ( ! isset($qtxtresult[0]['txt']) ) {
                $qtxtresult[0]['txt'] = "";
            }
            $blList[$counter]=$ip.' is listed in ('.$rbl.')';
            echo '...........Listed in -'.$rbl.'<br />';                
        }
        echo str_repeat(" ", 24), "\n";

        $counter++;
    }
}
}
?>
4

1 回答 1

0

此代码已包含在 dnsbl.tornevall.org 的源代码片段中(可通过https://dnsbl.tornevall.org/download/下载),如果 ip 被列入黑名单,则返回一个数组。它还支持 ipv6。如果它被列入黑名单,$result[3] 有一个正值,即位掩码,位掩码值取决于该 ip 被标记为的黑名单类型。

在这个例子中,我使用了一个我知道在域中被列入黑名单的随机 ip。不幸的是,该脚本不支持 TXT 查找,但如果您只需要阻止来自列入黑名单的 IP 地址的连接,该脚本也是非常基本的。

function rblresolve ($ip = '', $rbldomain = '')
{
        if (!$ip) {return false;}                       // No data should return nothing
        if (!$rbldomain) {return false;}        // No rbl = ignore

        // Old function (during betatesting we want to keep those rows so we can fall back if something fails)
        // $returnthis = explode('.', gethostbyname(implode('.', array_reverse(explode('.', $ip))) . '.' . $rbldomain));           // Not ipv6-compatible!
        // if (implode(".", $returnthis) != implode('.', array_reverse(explode('.', $ip))) . '.' . $rbldomain) {return $returnthis;} else {return false;}

        // New ipv6-compatible function
        $returnthis = (long2ip(ip2long($ip)) != "0.0.0.0" ? explode('.', gethostbyname(implode('.', array_reverse(explode('.', $ip))) . '.' . $rbldomain)) : explode(".", gethostbyname(v6arpa($ip) . "." . $rbldomain)));
        // 127-bug-checking
            if (implode(".", $returnthis) != (long2ip(ip2long($ip)) != "0.0.0.0" ? implode('.', array_reverse(explode('.', $ip))) . '.' . $rbldomain : v6arpa($ip) . "." . $rbldomain)) {return $returnthis;} else {return false;}
}

function v6arpa($ip)
{
        $unpack = unpack('H*hex', inet_pton($ip));
        $hex = $unpack['hex'];
        return implode('', array_reverse(str_split($hex)));
}

$result = rblresolve("117.197.11.203", "dnsbl.tornevall.org");
print_r($result);

返回:

Array
(
    [0] => 127
    [1] => 0
    [2] => 0
    [3] => 67

)

于 2014-10-26T11:48:56.443 回答