Moonbat
05-11-2008, 07:40 PM
Okay well, I managed to make a portscanner that can take one port and scan a host to see if it is open or not. I tried to expand it so that the user could put in a range of ports to scan, but it doesn't work. Here is my code:
<?php
/* PHP Port Scanner */
/* Coded by Moonbat */
/* May 5, 2008 */
if (isset($_POST['portdatauno'])) {
for ($i = $portdatauno; $i <= $portdatados; $i++) {
$portdatauno = $_POST['portdatauno'];
$portdatados = $_POST['portdatados'];
$hostdata = $_POST['hostdata'];
$scan = @fsockopen("$hostdata", $i, $errno, $errstr, *00000000000000000000000);
if($scan) {
echo "Port " . $i . " is <font color=\"green\"><b>OPEN</b></font> on " . $hostdata . "!";
echo "<br>";
} else {
echo "Port " . $i . " is <font color=\"red\"><b>CLOSED</b></font> on " . $hostdata . "!";
echo "<br>";
}
}
flush();
} else {
echo <<< HTMLONE
<html>
<head>
<title>PHP Port Scanner - Coded By Moonbat</title>
<style type="text/css">
body
{
background-color : #000000
}
h*
{
color : #CCCC00;
text-align: center;
}
p
{
color : #CCCC00;
text-align : center;
}
textarea
{
background-color : #CCCC00;
text : #000000;
}
input
{
background-color : #CCCC00;
}
</style>
</head>
<body>
<font face = "Verdana"><h*>PHP Port Scanner</h*></font>
<center<font color = "CCCC00"><h*>Coded By Moonbat</h*></font></center>
<form action = "$PHP_SELF" method = "POST" name = "PortScanData"
<br>
<p><b>HOSTNAME</b> (ex: google.com) </p>
<center><input type = "text" name = "hostdata" /></center
<p><b>PORT NUMBER RANGE</b> (ex. To scan *-20, put * in first box, and 20 in second box)
<center><input type = "text" maxlength = "4" size = "4" name = "portdatauno" /></center>
<p>TO</p>
<center><input type = "text" maxlength = "4" size = "4" name = "portdatados" /></center>
<br><br>
<center><input type = "Submit" value = "Initiate Port Scan" /></center>
</form>
</body>
</html>
HTMLONE;
}
?>
It states that all ports are closed. I've tried tons of differnt ways of doing this. But even when scanning obviously open ports like port 80 on google.com I get closed. I've been using WAMP to test this, and I know that my code should be right because it works with single ports. But the minute I try to use a loop to scan a certain range, it messes up and doesn't work at all.
Can anyone help me? :o
<?php
/* PHP Port Scanner */
/* Coded by Moonbat */
/* May 5, 2008 */
if (isset($_POST['portdatauno'])) {
for ($i = $portdatauno; $i <= $portdatados; $i++) {
$portdatauno = $_POST['portdatauno'];
$portdatados = $_POST['portdatados'];
$hostdata = $_POST['hostdata'];
$scan = @fsockopen("$hostdata", $i, $errno, $errstr, *00000000000000000000000);
if($scan) {
echo "Port " . $i . " is <font color=\"green\"><b>OPEN</b></font> on " . $hostdata . "!";
echo "<br>";
} else {
echo "Port " . $i . " is <font color=\"red\"><b>CLOSED</b></font> on " . $hostdata . "!";
echo "<br>";
}
}
flush();
} else {
echo <<< HTMLONE
<html>
<head>
<title>PHP Port Scanner - Coded By Moonbat</title>
<style type="text/css">
body
{
background-color : #000000
}
h*
{
color : #CCCC00;
text-align: center;
}
p
{
color : #CCCC00;
text-align : center;
}
textarea
{
background-color : #CCCC00;
text : #000000;
}
input
{
background-color : #CCCC00;
}
</style>
</head>
<body>
<font face = "Verdana"><h*>PHP Port Scanner</h*></font>
<center<font color = "CCCC00"><h*>Coded By Moonbat</h*></font></center>
<form action = "$PHP_SELF" method = "POST" name = "PortScanData"
<br>
<p><b>HOSTNAME</b> (ex: google.com) </p>
<center><input type = "text" name = "hostdata" /></center
<p><b>PORT NUMBER RANGE</b> (ex. To scan *-20, put * in first box, and 20 in second box)
<center><input type = "text" maxlength = "4" size = "4" name = "portdatauno" /></center>
<p>TO</p>
<center><input type = "text" maxlength = "4" size = "4" name = "portdatados" /></center>
<br><br>
<center><input type = "Submit" value = "Initiate Port Scan" /></center>
</form>
</body>
</html>
HTMLONE;
}
?>
It states that all ports are closed. I've tried tons of differnt ways of doing this. But even when scanning obviously open ports like port 80 on google.com I get closed. I've been using WAMP to test this, and I know that my code should be right because it works with single ports. But the minute I try to use a loop to scan a certain range, it messes up and doesn't work at all.
Can anyone help me? :o