svn: /pear/packages/Net_Portscan/tags/ Net_Portscan-1.0.3/Portscan.php Net_Portscan-1.0.3/README.portscan Net_Portscan-1.0.3/tests/01-portscan.php

From: Date: Mon, 21 Dec 2009 21:05:18 +0000
Subject: svn: /pear/packages/Net_Portscan/tags/ Net_Portscan-1.0.3/Portscan.php Net_Portscan-1.0.3/README.portscan Net_Portscan-1.0.3/tests/01-portscan.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-58343@lists.php.net to get a copy of this message
mj Mon, 21 Dec 2009 21:05:18 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=292448 Log: Tagging the 1.0.3 release Changed paths: A pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/ A + pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/Portscan.php (from pear/packages/Net_Portscan/trunk/Portscan.php:r292446) A + pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/README.portscan (from pear/packages/Net_Portscan/trunk/README.portscan:r292444) A pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/tests/ A + pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/tests/01-portscan.php (from pear/packages/Net_Portscan/trunk/tests/01-portscan.php:r292444) Copied: pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/Portscan.php (from rev 292446, pear/packages/Net_Portscan/trunk/Portscan.php) =================================================================== --- pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/Portscan.php (rev 0) +++ pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/Portscan.php 2009-12-21 21:05:18 UTC (rev 292448) @@ -0,0 +1,138 @@ +<?php +/** + * PHP 4 + * + * Copyright (c) 1997-2003 The PHP Group + * + * This source file is subject to version 2.0 of the PHP license, + * that is bundled with this package in the file LICENSE, and is + * available at through the world-wide-web at + * http://www.php.net/license/2_02.txt. + * If you did not receive a copy of the PHP license and are unable to + * obtain it through the world-wide-web, please send a note to + * license@php.net so we can mail you a copy immediately. + * + * Authors: Martin Jansen <mj@php.net> + * + * @category Net + * @package Net_Portscan + * @author Martin Jansen <mj@php.net> + * @license PHP 2.02 <http://www.php.net/license/2_02.txt> + * @version CVS: $Id$ + * @link http://pear.php.net/net_portscan + */ + +define("NET_PORTSCAN_SERVICE_FOUND", true); +define("NET_PORTSCAN_NO_SERVICE", false); + +/** + * Portscan class + * + * This class provides methods to scan ports on machines, + * that are connected to the internet. See README for more + * information on how to use it. + * + * @category Net + * @package Net_Portscan + * @author Martin Jansen <mj@php.net> + * @license PHP 2.02 <http://www.php.net/license/2_02.txt> + * @link http://pear.php.net/net_portscan + */ +class Net_Portscan +{ + // {{{ checkPort() + + /** + * Check if there is a service available at a certain port. + * + * This function tries to open a connection to the port + * $port on the machine $host. If the connection can be + * established, there is a service listening on the port. + * If the connection fails, there is no service. + * + * @param string $host Hostname + * @param integer $port Portnumber + * @param integer $timeout Timeout for socket connection in seconds + * (default is 30). + * + * @access public + * @return string + */ + function checkPort($host, $port, $timeout = 30) + { + $socket = @fsockopen($host, $port, $errorNumber, $errorString, $timeout); + + if (!$socket) { + return NET_PORTSCAN_NO_SERVICE; + } + + @fclose($socket); + return NET_PORTSCAN_SERVICE_FOUND; + } + + // }}} + // {{{ checkPortRange() + + /** + * Check a range of ports at a machine + * + * This function can scan a range of ports (from $minPort + * to $maxPort) on the machine $host for running services. + * + * @param string $host Hostname + * @param integer $minPort Lowest port + * @param integer $maxPort Highest port + * @param integer $timeout Timeout for socket connection in seconds + * (default is 30). + * + * @access public + * + * @return array Associative array containing the result + */ + function checkPortRange($host, $minPort, $maxPort, $timeout = 30) + { + for ($i = $minPort; $i <= $maxPort; $i++) { + $retVal[$i] = Net_Portscan::checkPort($host, $i, $timeout); + } + + return $retVal; + } + + // }}} + // {{{ getService() + + /** + * Get name of the service that is listening on a certain port. + * + * @param integer $port Portnumber + * @param string $protocol Protocol (Is either tcp or udp. Default is tcp.) + * + * @access public + * + * @return string Name of the Internet service associated with $service + */ + function getService($port, $protocol = "tcp") + { + return @getservbyport($port, $protocol); + } + + // }}} + // {{{ getPort() + + /** + * Get port that a certain service uses. + * + * @param string $service Name of the service + * @param string $protocol Protocol (Is either tcp or udp. Default is tcp.) + * + * @access public + * + * @return integer Internet port which corresponds to $service + */ + function getPort($service, $protocol = "tcp") + { + return @getservbyname($service, $protocol); + } + + // }}} +} Property changes on: pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/Portscan.php ___________________________________________________________________ Added: svn:executable + * Added: cvs2svn:cvs-rev + 1.5 Added: svn:keywords + Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL Added: svn:mergeinfo + Added: svn:eol-style + native Copied: pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/README.portscan (from rev 292444, pear/packages/Net_Portscan/trunk/README.portscan) =================================================================== --- pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/README.portscan (rev 0) +++ pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/README.portscan 2009-12-21 21:05:18 UTC (rev 292448) @@ -0,0 +1,3 @@ +The documentation for Net_Portscan is available at + + http://pear.php.net/manual/ Property changes on: pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/README.portscan ___________________________________________________________________ Added: svn:executable + * Added: cvs2svn:cvs-rev + 1.1 Added: svn:keywords + Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL Added: svn:mergeinfo + Added: svn:eol-style + native Copied: pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/tests/01-portscan.php (from rev 292444, pear/packages/Net_Portscan/trunk/tests/01-portscan.php) =================================================================== --- pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/tests/01-portscan.php (rev 0) +++ pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/tests/01-portscan.php 2009-12-21 21:05:18 UTC (rev 292448) @@ -0,0 +1,29 @@ +<?php +/** $Id$ */ +require_once "Net/Portscan.php"; + +/** Test for checkPort() and getService() */ +if (Net_Portscan::checkPort("localhost", 80) == NET_PORTSCAN_SERVICE_FOUND) { + echo "There is a service on your machine on port 80 (" . Net_Portscan::getService(80) . ").\n"; +} + +/** Test for checkPortRange() */ +echo "Scanning localhost ports 70-90\n"; +$result = Net_Portscan::checkPortRange("localhost", 70, 90); + +foreach ($result as $port => $element) { + echo "Port " . $port . ": "; + if ($element == NET_PORTSCAN_SERVICE_FOUND) { + echo " Service found.\n"; + } else { + echo " No service found.\n"; + } +} + +/** Test for getService() */ +echo "On port 22, there service " . Net_Portscan::getService(22) . " is running.\n"; + +/** Test for getPort() */ +echo "The finger service usually runs on port " . Net_Portscan::getPort("finger") . ".\n"; + +?> Property changes on: pear/packages/Net_Portscan/tags/Net_Portscan-1.0.3/tests/01-portscan.php ___________________________________________________________________ Added: svn:executable + * Added: cvs2svn:cvs-rev + 1.2 Added: svn:keywords + Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL Added: svn:mergeinfo + Added: svn:eol-style + native

« previous php.pear.cvs (#58343) next »