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
Example.phpCode:<?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";
}
}
}
?>
WEB.IOType.phpCode:<?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");
}
?>
ports.cssCode:<?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>";
?>
CLI.IOType.phpCode: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;
}
Library.IOType.phpCode:<?php
for($i=20;$i<=111;$i++){
$result = $MyIOType->Check($MyHost,$i);
echo $i . "::" . $result["port"] . "[" . $result["default"]["type"] . "] " . $result["type"] . " " . $result["truetype"] . "\n";
}
?>
Download
Well, mine was just a tutorial.![]()
Why not attach all of the files as one zip file?
Nice codeIt would be nice if I didn't have to use my cell phone to scan ports lol.
Our University firewall blocks these types of programs :/
SSH Tunneling being my favorite. If SSH is blocked, setup an SSH server on an unblocked port such as 80.
I use ssh occasionally to tunnel, but since my cell connection can stay on 24x7, so I just prefer to use that (its a simple button click to access it) lol.
I guess my point is, if you think a port should show up but doesn't, check your firewall.
thanks
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks