cvs: pear /Net_Portscan Portscan.php README package.xml test.php

From: Date: Thu, 15 Nov 2001 20:56:48 +0000
Subject: cvs: pear /Net_Portscan Portscan.php README package.xml test.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1327@lists.php.net to get a copy of this message
mj Thu Nov 15 15:56:48 2001 EDT Added files: /pear/Net_Portscan Portscan.php test.php package.xml README Log: * Initial checkin of Net_Portscan class. Index: pear/Net_Portscan/Portscan.php +++ pear/Net_Portscan/Portscan.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001 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> | // | | // +----------------------------------------------------------------------+ // // $Id: Portscan.php,v 1.1 2001/11/15 20:56:48 mj Exp $ 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. * * @author Martin Jansen <mj@php.net> * @version $Revision: 1.1 $ */ 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. * * @access public * @param string Hostname * @param integer Portnumber * @param integer Timeout for socket connection in seconds (default is 30). * @return string */ function checkPort($host, $port, $timeout = 30) { $socket = @fsockopen($host, $port, $errorNumber, $errorString, $timeout); if (!$socket) { return NET_PORTSCAN_NO_SERVICE; } 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. * * @access public * @param string Hostname * @param integer Lowest port * @param integer Highest port * @param integer Timeout for socket connection in seconds (default is 30). * @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. * * @access public * @param integer Portnumber * @param string Protocal (default is tcp) * @return string Name of the service */ function getService($port, $protocol = "tcp") { return @getservbyport($port, $protocol); } // }}} // {{{ getPort() /** * Get port that a certain service uses. * * @access public * @param string Name of the service * @param string Protocal (default is tcp) * @return integer Portnumber */ function getPort($service, $protocol = "tcp") { return @getservbyname($service, $protocol); } // }}} } ?> Index: pear/Net_Portscan/test.php +++ pear/Net_Portscan/test.php <?php /** $Id: test.php,v 1.1 2001/11/15 20:56:48 mj Exp $ */ require_once "Net_Portscan/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) { if ($element == NET_PORTSCAN_SERVICE_FOUND) { echo "On port " . $port . " there is running a service.\n"; } else { echo "On port " . $port . " there is no service running.\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"; ?> Index: pear/Net_Portscan/package.xml +++ pear/Net_Portscan/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!-- do not use the "Type" attribute here, that one is only for generated package.xml files --> <package> <name>Net_Portscan</name> <summary>Portscanner utilities.</summary> <maintainer> <user>MJ</user> <name>Martin Jansen</name> <email>mj@php.net</email> </maintainer> <release> <version>1.0</version> <date>2001-11-15</date> <notes> This is the first stable release. </notes> </release> <filelist> <dir name="/" baseinstalldir="Net_Portscan"> <file role="php">Portscan.php</file> <file role="php">test.php</file> <file role="text">README</file> </dir> </filelist> </package>

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