<?php
/* nstest - determine dns servers used by visitors
 *
 * author: apoc <apoc@sixserv.org>
 * site: http://apoc.sixserv.org/
 * license: GPLv3
 **/
?>
<?= 
'<?xml version="1.0"?>' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>DNS Tester</title>
<script type="text/javascript" src="prototype.js"></script>
<style>

*
{
    font-family: Courier;
    font-size: 14px;
}

input, select
{
    font-size: 16px;
    font-weight: bold;
    padding: 5px;
    margin-right: 5px;
}

</style>
</head>
<body onload="test_onload();">

<noscript>
<h1>ACTIVATE JAVASCRIPT!</h1>
</noscript>

<h1>DNS Resolve Tester</h1>


How many tests?
<form method="POST" action="">
<select name="no">
    <option selected="selected">1</option>
    <option>2</option>
    <!-- <option>4</option>
    <option>8</option> -->
</select><input type="submit" value="do!" />
</form>

<?php

function create_rand_hash()
{
    
$garbage "";
    for(
$i 0$i<100$i++)
        
$garbage .= rand(0,1000);
    return 
md5($garbage);
}

if(!empty(
$_POST["no"])) {

    
$no $_POST["no"];
    if(!
is_numeric($no) or $no or $no 1) {
        die(
"Input Validation Error");
        exit;
    } else {
        echo 
"* Testing $no times...<br />\n";
        
ob_flush();

?><script type="text/javascript">

function ask_for_results(hsh)
{
    var elm = document.getElementById('resultdiv');
    if(elm != null)
    {
        //alert("ajax!!!");
        elm.style.display = 'block';
        //elm.innerHTML += 'foo!<br /><br />bar';

        ( new Ajax.Request("result.php", {
            method: "post",
            parameters: {hash: hsh},
            onSuccess: function(transport) {
                var response = transport.responseText;
                elm.innerHTML += response;
            }
        } ));
    }

}

</script><?php

        
for($i 0$i $no$i++) {
            
$test create_rand_hash();
            echo 
"* Test No. $i...";
            echo 
"<iframe onload=\"ask_for_results('$test');\" src=\"http://$test.nstest.4poc.org/zero\" width=\"0\" height=\"0\"></iframe>";
            echo 
"<br />\n";
            
ob_flush();
        }

        echo 
"<br />... Waiting for Results ... This could take some time ...<br /><br />\n";

        echo 
'<div id="resultdiv" style="display: none;"><b>You('.$_SERVER["REMOTE_ADDR"].' ['.gethostbyaddr($_SERVER["REMOTE_ADDR"]).']) are using the following DNS-Servers:</b><br /></div>';

        
ob_flush();
    }
}

?>

For more information: http://nstest.4poc.org/

</body>
</html>