Class PHP Port Scan CR7
Program Name : Class PHP Port Scan CR7
Program Language : PHP
Author : Christian Ditaputratama
License : Open Source, FREE for FREEDOM under GNU GPL License.
Concept : Web based scanning tools for single or multiple OPEN or CLOSED port to target host.
Disclaimer : This script are often used solely for informative, educational purposes only. Author cannot be held responsible for any damage and (or) (ab)use of these script.
Please submit changes of the script so other people can use them as well. This script is free to use, don’t abuse.

The PHP class
<?php
/**
* Class PHP Port Scan CR7
*
* @version 1.00
* @author Christian Ditaputratama <ditatompel@gmail.com>
*
* Scan for single or multiple OPEN or CLOSED port to target host
*
*------------------------------------------------------------------------+
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License version 2 as |
* published by the Free Software Foundation. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the |
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
* Boston, MA 02111-1307 USA |
* |
* This script are often used solely for informative, educational, or |
* entertainment purposes only. Author cannot be held responsible |
* for any damage and (or) (ab)use of these script. |
* Please submit changes of the script so other people can use |
* them as well. This script is free to use, don't abuse. |
*------------------------------------------------------------------------+
*/
class crPortScan {
/**
* Target port for single scanning
*
* @var integer
*/
var $port;
/**
* Target host you want to scan
*
* @var mixed
*/
var $host;
/**
* the port list file location
*
* You can add your self
* The port list structure should be {port:service}
*
* @var string
*/
var $port_list;
function status() {
$sc = socket_create(AF_INET, SOCK_STREAM, getprotobyname("TCP"));
if ( !@socket_connect($sc, $this->host, $this->port) ) :
$this->result="<span style=\"color:red\">CLOSED</span>";
else :
$this->result="<span style=\"color:green\">OPEN</span>";
endif;
}
function single_scan() {
$this->status();
$this->scan_result = $this->host . ":" . $this->port . " status : " . $this->result . "<br />";
}
function full_scan() {
if(!is_file($this->port_list)) {
exit('Error : Port list not found');
}
$openList = fopen($this->port_list, 'r');
$byLine = fread($openList, filesize($this->port_list));
fclose($openList);
$byLine = explode("\n", $byLine);
for ($i=0; $i<sizeof($byLine); $i++) {
$data = explode(":", $byLine[$i]);
if($data[0] != NULL) {
$this->port = $data[0];
$this->status();
$this->full_scan_result[$i] = $this->host . ":" . $this->port . " (" . $data[1] . ") status : " . $this->result . "<br />";
}
}
}
}
?>
Usage Example
<?php
require ('class.portscan.php');
$scan=new crPortScan;
$scan->port = 21;
$scan->host = "second-heartbeat";
/**
* for single scan
*
* Required : port, host
*/
echo "Single scan example :<br />";
$scan->single_scan();
echo $scan->scan_result;
/**
* For multiple scan
*
* Required : port_list, host
*/
echo "<br />Multiple port scan example:<br />";
$scan->port_list = "portscan-list.txt";
$scan->full_scan();
print "Total available data on portlist : " . sizeof($scan->full_scan_result)."<br />";
for($i=0; $i<sizeof($scan->full_scan_result); $i++) {
echo $scan->full_scan_result[$i];
}
?>
Of course you can improve it with form and ajax request.

