3

i have this function written in 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']);
}
?>

and what this does it checks an IP if is listed on certain blacklists

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!

bu i have a little problem, i want to flush the output every time a check has been made, how can i do this?

The first thing that happen when the script runs, i wait 20 secs and then 20 checks pops up, then 1 per second, why is that?

Any help would be appreciated.

hakre
  • 193,403
  • 52
  • 435
  • 836
Master345
  • 2,250
  • 11
  • 38
  • 50
  • Is this what you want to achieve : http://codepad.viper-7.com/76Amxe – Baba Oct 15 '12 at 18:16
  • same thing, what i want is 1 ip per second check, one by one, one after another, get me? – Master345 Oct 15 '12 at 18:53
  • You want to make it something like a progress bar right ??? – Baba Oct 15 '12 at 20:06
  • xampp, and now i'm working on a different approach, i'm trying to use ajax and request DNSBL one by one http://codepad.org/gmJDLvIb, would you help me? here is a little bit of jquery – Master345 Oct 15 '12 at 20:18
  • Finally got it to work :) hold on – Baba Oct 15 '12 at 20:19
  • I used Firebug .. got to fine out that flush actually works ... but the browser waits for it to have a certain number (10) of content before its starts to display ... Use This http://codepad.viper-7.com/kCHQOx – Baba Oct 15 '12 at 20:26
  • that's why i have to use ajax callback, do you know jquery? – Master345 Oct 15 '12 at 20:28
  • Yes .... Using ajax is easy with this @Row Minds – Baba Oct 15 '12 at 20:29
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/18073/discussion-between-row-minds-and-baba) – Master345 Oct 15 '12 at 20:31

2 Answers2

1

This Concept works for me :)

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);
}
Baba
  • 94,024
  • 28
  • 166
  • 217
  • How would you combine this with the script the OP posted? I have the original script working, but am facing the same delay at the beginning. – Sherwin Flight Jun 02 '14 at 01:54
0

flush() doesn't appear to be part of "output buffering" (ob).. Use ob_flush(). Also there should be no need for ob_end() and ob_start() if you use the proper function. :)

void ob_flush ( void )

This function will send the contents of the output buffer (if any). If you want to further process the buffer's contents you have to call ob_get_contents() before ob_flush() as the buffer contents are discarded after ob_flush() is called.

This function does not destroy the output buffer like ob_end_flush() does.

Gung Foo
  • 13,392
  • 5
  • 31
  • 39
  • did you call `ob_start()` (once) at the beginning of your request? – Gung Foo Oct 15 '12 at 17:57
  • can you try it on your local please to see this? i have used flush and ob_flush before, but i don't know why this is not working – Master345 Oct 15 '12 at 18:00
  • there is no ob_start() in that code. and it throws an error: Warning: preg_match(): Internal pcre_fullinfo() error -3 on line 125... what are you smoking over there? :P – Gung Foo Oct 15 '12 at 18:01
  • :)) believe me, codepad is just for copy/paste at my local it works, and this http://codepad.org/WnyIYSDb have the same result, it output after the script is done – Master345 Oct 15 '12 at 18:03
  • hrm.. maybe not using ob is the way to go? http://stackoverflow.com/questions/4481235/php-flush-ob-flush-not-working – Gung Foo Oct 15 '12 at 18:10
  • and if i run this with `php script.php` in linux it may do what i want, but i want a webservice .. – Master345 Oct 15 '12 at 18:12