With below portscanner I try to 'flush' results when a port has been scanned in a table, but for some reason the table is created after all the ports have been scanned.
Also no matter how high or low I make the timeout, all the port scan results give a '110 error'(timeout)...
Does anyone have a suggestion?
Thanks in advance.
<?php
if(!isset($submit))
{
?>
<center><h3><b>Scan your system:</b></h3></center>
<blockquote><b>Make a range for all ports to be scanned, the time
for the scan depends on the amount of ports you choose to scan, also choose a low timeout to keep the scan shorter.</b>
</blockquote>
<form method="post" action="<?=$PHP_SELF?>">
<b>Your IP Address</b> <input type="text" name="host" value="<?=$REMOTE_ADDR?>"><p>
<b>Start scan at Port</b> <input type="text" name="laagste" maxlength="5" size="5"><p>
<b>End scan at Port</b> <input type="text" name="hoogste" maxlength="5" size="5"><p>
<b>Timeout value</b> <input type="text" name="timeout" maxlength="2" size="2"><p>
<input type="submit" name="submit" value="scan">
</form>
<?php
exit;
}
if($laagste=="")
{
echo"<center><b>You did not fill in all fields!</b><p><a href=\"<?=$HTTP_REFERER?>\">Try Again?</a></b></center>";
exit;
}
if($hoogste=="")
{
echo"<center><b>You did not fill in all fields!</b><p><a href=\"<?=$HTTP_REFERER?>\">Try Again?</a></b></center>";
exit;
}
if($timeout=="")
{
echo"<center><b>You did not fill in all fields!</b><p><a href=\"<?=$HTTP_REFERER?>\">Try Again?</a></b></center>";
exit;
}
set_time_limit(0);
//1024 is the maximum value, higher will be rejected
$totaalports = $hoogste - $laagste;
if($totaalports>1024)
{
echo"<b>You may scan up to 1024 ports at a time.</b><p><center><a href=\"<?=$HTTP_REFERER?>\"><b>Try again?</b></a></center>";
exit;
}
if ($submit=="scan")
{
$omgeving = getenv(REMOTE_ADDR);
if($host = gethostbyaddr($omgeving));
$result = strrchr($host, ".");
if(!$result || is_numeric($result))
{
echo"<b>I'd say lay back and take a beer or whatsoever, because this could take some time...<p>";
echo"If you have a firewall with an 'attack-prompt' like <a href=\"http://www.zonelabs.com\" target=\"_blank\">Zonelabs</a> you can see which ports already have been scanned.</b>";
flush();
}
else
{
echo"<b>If you haven't spoofed your ip-address your hostname is $result<p>";
echo"I'd say lay back and take a beer or whatsoever, because this could take some time...<p>";
echo"If you have a firewall with an 'attack-prompt' like <a href=\"http://www.zonelabs.com\" target=\"_blank\">Zonelabs</a> you can see which ports already have been scanned.</b>";
flush();
}
echo"<table border=\"1\"><tr><th>POORT</th><th>ERROR NUMMER</th><th>ERROR STRING</th><th>OPEN?</th></tr>";
flush();
$openports = 0;
for ($port = $laagste; $port <= $hoogste; $port++)
{
$socket = fsockopen($host, $port, $errno, $errstr, $timeout);
if ($socket>0)
{
echo"<tr><td>$port</td><td>$errno</td><td>$errstr</td><td>OPEN</td></tr>";
$openports = $openports + 1;
fclose($socket);
flush();
}
else
{
echo"<tr><td>$port</td><td>$errno</td><td>$errstr</td><td>STEALTH/CLOSED</td></tr>";
flush();
}
}
echo "</table></center>";
if($openports>0)
{
echo"<p>You'd better get yourself a copy of a <a href=\"http://www.zonelabs.com\" target=\"_blank\">firewall</a>...";
echo"You got one!? Then it's either corrupted or bad configurated...<p>";
echo"There were $openports open ports found.";
echo"<center>There's a slight chance someone placed a backdoor to your system.<p><a href=\"http://www.grc.com\" target=\"_blank\">Get rid of it?</a></center>";
}
if($openports<1)
{
echo"<p>Your system seems to have no open ports...good for you!<p><a href=\"http://www.tools-and-design.com/siteframe1.php?<?=SID?>\">Go back to Index?</a>";
}
}
?>