Location: PHPKode > scripts > Portscan > portscan/class.scan.php
<?php
	/*
	Date: 9-05-2006 15:57
	Author: B.Heesen (hide@address.com)
	Version: 0.1b
	© Cpyright 2006 De Bron Digital Solutions (http://www.dbds.nl)
	*/

class Scan
{
	var $ip;
	var $port;
	var $timeout;
	var $numports;
	var $openports;
	var $portstatus;
	var $portresponse;
	var $starttime;
	var $actualtime;
	var $totaltime;
	
	function Scan($ip,$timeout)
	{
		$this->ip = $ip;
		if($timeout > 0.01 && $timeout < 10) $this->timeout = $timeout;
		else $this->timeout = 0.5;
		$this->numports = 0;
		$this->openports = 0;
		$this->starttime = $this->mtime();
		$this->actualtime = 0;
		$this->totaltime = 0;
	}
	
	function portInfo($port)
	{
		flush();
		$this->port = $port;
		$time = $this->mtime();
		$fp = fsockopen ("$this->ip", $this->port, $errno, $errstr, $this->timeout);
		if(!$fp)
		{
			$this->portstatus = false;
			$this->porterror = $errno;
			$this->portresponse = $errstr." (".$errno.")";
		}
		else
		{
			if($this->port == 80)
			{
				fputs ($fp, "GET / HTTP/1.0\r\nHost: ".$this->ip."\r\n\r\n");
				for($i=0;$i<5;$i++)
				{ 
					$tmpresponse = fgets($fp,1024);
					if(ereg("Server",$tmpresponse)) $this->portresponse = $tmpresponse;
				}
			}
			else
			{
				$this->portresponse = fgets($fp,1024);
			}
			$this->portstatus = true;
			$this->openports++;
			fclose($fp);
		}
		$this->actualtime = $this->mtime() - $time;
		$this->totaltime = $this->mtime() - $this->starttime;
		$this->numports++;
	}
	
	function mtime()
	{ 
    	list($usec, $sec) = explode(" ",microtime()); 
    	return ((float)$usec + (float)$sec);
    }
}

?>
Return current item: Portscan