scan a range of ports

this uses the Net_PortScan PEAR package to check a range of ports to see if a service is available

<?php
require_once "/home/beginne/php/Net/Portscan.php";

echo "Scanning localhost ports 1-21<br>";
$result = Net_Portscan::checkPortRange("localhost", 1, 21);

foreach ($result as $port => $element)
{
if ($element == NET_PORTSCAN_SERVICE_FOUND)
{
echo "Service found on port " . $port . "<br>";
}
else
{
echo "No service found on port " . $port . "<br>";
}
}
?>