刷新用于IP黑名单检查的PHP脚本

时间:2012-10-15 17:46:33

标签: php web-services ip flush

我有用PHP编写的这个函数

<?php
/***************************************************************************************
This is a simple PHP script to lookup for blacklisted IP against multiple DNSBLs at once.

You are free to use the script, modify it, and/or redistribute the files as you wish.

Homepage: http://dnsbllookup.com
****************************************************************************************/
function flush_buffers(){ 
    ob_end_flush(); 
    flush(); 
    ob_start(); 
} 

function dnsbllookup($ip)
{
    $dnsbl_lookup=array(
    "access.redhawk.org",
    "b.barracudacentral.org",
    "bl.csma.biz",
    "bl.emailbasura.org",
    "bl.spamcannibal.org",
    "bl.spamcop.net",
    "bl.technovision.dk",
    "blackholes.five-ten-sg.com",
    "blackholes.wirehub.net",
    "blacklist.sci.kun.nl",
    "block.dnsbl.sorbs.net",
    "blocked.hilli.dk",
    "bogons.cymru.com",
    "cart00ney.surriel.com",
    "cbl.abuseat.org",
    "dev.null.dk",
    "dialup.blacklist.jippg.org",
    "dialups.mail-abuse.org",
    "dialups.visi.com",
    "dnsbl.ahbl.org",
    "dnsbl.antispam.or.id",
    "dnsbl.cyberlogic.net",
    "dnsbl.kempt.net",
    "dnsbl.njabl.org",
    "dnsbl.sorbs.net",
    "dnsbl-1.uceprotect.net",
    "dnsbl-2.uceprotect.net",
    "dnsbl-3.uceprotect.net",
    "duinv.aupads.org",
    "dul.dnsbl.sorbs.net",
    "dul.ru",
    "escalations.dnsbl.sorbs.net",
    "hil.habeas.com",
    "http.dnsbl.sorbs.net",
    "intruders.docs.uu.se",
    "ips.backscatterer.org",
    "korea.services.net",
    "mail-abuse.blacklist.jippg.org",
    "misc.dnsbl.sorbs.net",
    "msgid.bl.gweep.ca",
    "new.dnsbl.sorbs.net",
    "no-more-funn.moensted.dk",
    "old.dnsbl.sorbs.net",
    "pbl.spamhaus.org",
    "proxy.bl.gweep.ca",
    "psbl.surriel.com",
    "pss.spambusters.org.ar",
    "rbl.schulte.org",
    "rbl.snark.net",
    "recent.dnsbl.sorbs.net",
    "relays.bl.gweep.ca",
    "relays.bl.kundenserver.de",
    "relays.mail-abuse.org",
    "relays.nether.net",
    "rsbl.aupads.org",
    "sbl.spamhaus.org",
    "smtp.dnsbl.sorbs.net",
    "socks.dnsbl.sorbs.net",
    "spam.dnsbl.sorbs.net",
    "spam.olsentech.net",
    "spamguard.leadmon.net",
    "spamsources.fabel.dk",
    "tor.ahbl.org",
    "web.dnsbl.sorbs.net",
    "whois.rfc-ignorant.org",
    "xbl.spamhaus.org",
    "zen.spamhaus.org",
    "zombie.dnsbl.sorbs.net",
    "bl.tiopan.com",
    "dnsbl.abuse.ch",
    "tor.dnsbl.sectoor.de",
    "ubl.unsubscore.com",
    "cblless.anti-spam.org.cn",
    "dnsbl.tornevall.org",
    "dnsbl.anticaptcha.net",
    "dnsbl.dronebl.org"
    ); // Add your preferred list of DNSBL's

    $AllCount = count($dnsbl_lookup);
    $BadCount = 0;
    if($ip)
    {
        $reverse_ip = implode(".", array_reverse(explode(".", $ip)));
        foreach($dnsbl_lookup as $host)
        {
            if(checkdnsrr($reverse_ip.".".$host.".", "A"))
            {
                echo "<span color='#339933'>Listed on ".$reverse_ip.'.'.$host."!</span><br/>";
                flush_buffers();
                $BadCount++;
            }
            else
            {
                echo "Not listed on ".$reverse_ip.'.'.$host."!<br/>";
                flush_buffers();
            }
        }
    }
    else
    {
        echo "Empty ip!<br/>";
        flush_buffers();
    }

    echo "This ip has ".$BadCount." bad listings of ".$AllCount."!<br/>";
    flush_buffers();

}

if(preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/",@$_GET['ip']) == true)
{
    dnsbllookup($_GET['ip']);
}
?>

以及它检查IP是否在某些黑名单上列出

http://127.0.0.1/check4_html.php?ip=123.123.123.123

Not listed on 123.123.123.123.access.redhawk.org!
Not listed on 123.123.123.123.b.barracudacentral.org!
Not listed on 123.123.123.123.bl.csma.biz!
Not listed on 123.123.123.123.bl.emailbasura.org!

我有一点问题,我想在每次检查时刷新输出,我该怎么做?

当脚本运行时发生的第一件事,我等待20秒,然后弹出20个检查,然后每秒1次,为什么会这样?

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:1)

这个概念对我有用:)

ini_set('output_buffering','on');
ini_set('zlib.output_compression', 0);
ini_set('implicit_flush',1);
ob_implicit_flush();

echo ("<html><head><head><body>");
for($i=0;$i<20;$i++) {
      echo $i;
      echo str_repeat(" ", 500);
      ob_flush();
      flush();
      sleep(1);
}

答案 1 :(得分:0)

flush()似乎不属于&#34;输出缓冲&#34; (OB).. 使用ob_flush()。如果您使用正确的功能,也不需要ob_end()ob_start()。 :)

  
    

void ob_flush(void)

  
     

此函数将发送输出缓冲区的内容(如果有)。如果   你想进一步处理你必须调用的缓冲区内容   ob_get_contents()在ob_flush()之前作为缓冲区内容   在调用ob_flush()之后丢弃。

     

此函数不会破坏输出缓冲区,如ob_end_flush()   确实