In an attempt to one-up John (
) I made this little PHP Port scanner.
You can host it on your site or standalone, and it will work from both the command line and the web (Although the web interface is a lot prettier.)
The way it is right now, it just checks the IP of whoever loads the page.
Currently includes port types and definitions for roughly 48000 ports.
Class.IOType.php
Code:
<?php
if(!defined("__IOType")) die("-_-");
class IOType
{
public $GUESS = false;
public $PORTS;
function Assign($ports){
$this->PORTS = $ports;
}
function Check($hostname,$port = 80){
$fp = @fsockopen($hostname, $port, $errno, $errstr, 1);
$ret["hostname"] = $hostname;
$ret["port"] = $port;
$ret["guess"] = $this->GUESS;
$ret["default"] = $this->PORTS[$port];
if($fp){
$ret["type"] = "OPEN";
if(!$this->GUESS){
$ret["truetype"]= $this->ident($fp);
return $ret;
}else{
return $this->ident($fp);
}
}else{
$ret["type"] = "CLOSED";
return $ret;
}
}
function lookup($port){
return $fake;
}
function ident($fp){
stream_set_timeout($fp,2);
// $raw = fread($fp,3);
fclose($fp);
switch($raw){
case "SSH":
return "SSH";
case "+OK":
return "POP3";
}
}
}
?>
Example.php
Code:
<?php
define("__IOType",TRUE);
global $LibIOType;
global $MyIOType;
global $MyHost;
$MyHost = (!$_SERVER['SERVER_ADDR']) ? "127.0.0.1" :
getenv(REMOTE_ADDR);
include_once("Class.IOType.php");
include_once("Library.IOType.php");
$MyIOType = new IOType;
$MyIOType->Assign($LibIOType);
if(empty($_SERVER['SERVER_ADDR'])){
include_once("CLI.IOType.php");
}else{
include_once("WEB.IOType.php");
}
?>
WEB.IOType.php
Code:
<?php
echo
"<HTML>\n
<head>\n
<title>TK Port Scan@Codecall.net</title>\n
<link rel=\"stylesheet\" type=\"text/css\" href=\"ports.css\" />
<SCRIPT TYPE=\"text/javascript\" LANGUAGE=\"javascript\">
function waitPreloadPage() { //DOM
if (document.getElementById){
document.getElementById('prepage').style.visibility='hidden';
}else{
if (document.layers){ //NS4
document.prepage.visibility = 'hidden';
}
else { //IE4
document.all.prepage.style.visibility = 'hidden';
}
}
}
</SCRIPT>
</head>\n
<body onLoad=\"waitPreloadPage();\">\n
<DIV id=\"prepage\" style=\"position:absolute; font-family:arial; font-size:16; left:0px; top:0px;
background-color:white; layer-background-color:white; height:100%; width:100%;\">
<TABLE width=100%><TR><TD><B>Loading ... ...</B></TD></TR></TABLE>
</DIV>
<center><a href=\"Example.php?type=all\">All Ports</a> | <a href=\"Example.php?type=open\">Open Ports</a> | <a
href=\"Example.php?type=sec\">Summary</a></center>
<table class=\"servicesT\" cellspacing=\"0\">\n
<tr><td colspan=\"3\" class=\"servHd\">Port Scan Results</td></tr>\n
";
for($i=20;$i<=4000;$i++){
$result = $MyIOType->Check($MyHost,$i);
if(!($result["type"] == "CLOSED" && $_GET["type"] == "open")){
if($result["type"] == "OPEN")
$color = "color: #FF0000;";
else
$color = "color: #3EA99F;";
echo "<tr>
<td>$i</td>
<td class=\"servBodL\"><b>{$result["default"]["type"]}</b></td>
<td class=\"servBodL\" style=\"$color\" width=\"10%\"><b>{$result["type"]}</b></td></tr>";
if(!empty($result["default"]["desc"])){
echo "
<tr>
<td></td>
<td colspan=\"3\"><i>{$result["default"]["desc"]}</i></td>
</tr>
";
}
}
}
echo
"
<tr><td colspan=\"3\" class=\"servHd\"><- Comming soon to a theater near you! -></td></tr>\n
</table>";
?>
ports.css
Code:
table.servicesT
{ font-family: Verdana;
font-weight: normal;
font-size: 11px;
color: #404040;
width: 100%;
background-color: #fafafa;
border: 1px #6699CC solid;
border-collapse: collapse;
border-spacing: 0px;
margin-top: 0px;}
table.servicesT td.servHd
{ border-bottom: 2px solid #6699CC;
background-color: #BEC8D1;
text-align: center;
font-family: Verdana;
font-weight: bold;
font-size: 11px;
color: #404040;}
table.servicesT td
{ border-bottom: 1px dotted #6699CC;
font-family: Verdana, sans-serif, Arial;
font-weight: normal;
font-size: 11px;
color: #404040;
background-color: white;
text-align: left;
padding-left: 3px;}
.servBodL { border-left: 1px dotted #CEDCEA; }
.open {
color: #FF0000;
}
.closed {
color: #3EA99F;
}
CLI.IOType.php
Code:
<?php
for($i=20;$i<=111;$i++){
$result = $MyIOType->Check($MyHost,$i);
echo $i . "::" . $result["port"] . "[" . $result["default"]["type"] . "] " . $result["type"] . " " . $result["truetype"] . "\n";
}
?>
Library.IOType.php
Download
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum