<?php
// Posted at http://www.w3tools.info/2011/12/simple-port-scanner-php.html
require("header.php");
$host = $_POST['host'];
$start = $_POST['start'];
$end = $_POST['end'];
$proto = $_POST['protocol'];
$serv = $_POST['services'];
?>
<html>
<body>
<div class="box">
<h2>Port Scanner</h2>
<div class="box-content">
<center>
<p><form name='scanner' method='post' action='<?php echo $PHP_SELF; ?>'>
Host name or IP:
<input type='text' name='host' value='<?php echo $host; ?>' /><br/>Starting Port: <input type='text' name='start' value='<?php echo $start; ?>' /><br/>Ending Port: <input type='text' name='end' value='<?php echo $end; ?>' /><br/>Protocol: <select name='protocol'>
<option value='tcp'>tcp</option>
<option value='udp'>udp</option>
</select>
<br/>Show services: <input name='services' type='checkbox' value='yes' /><br/><input type='submit' value='Scan Ports' />
<br /><br />
</center>
</div>
</div>
<div class="box">
<h2>Results:</h2>
<div class="box-content">
<center>
<?php
if(isset($host) && isset($start) && isset($end) && isset($proto))
{
echo "<strong></strong><br />";
for($current = $start; $current <= $end; $current++)
{
if($serv == "yes")
{
$service = getservbyport($current, $proto);
}
$result = fsockopen($host, $current, $errno, $errstr, 1);
if($serv == "yes")
{
echo "Port: <strong>".$current."</strong> is commonly used for: <strong>".$service."</strong> and was ";
}
else
{
echo "Port: <strong>".$current."</strong> was ";
}
if($result)
{
echo "<font color='green'><strong>OPEN</strong></font><br />";
}
else
{
echo "<font color='red'><strong>CLOSED</strong></font><br />";
}
}
}
?>
</center>
</div>
</div>
<?php
include 'footer.php';
?>