PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Networking » Net_Portscan » Manual

Provides an API for scanning ports

Net_Portscan::checkPort()

Net_Portscan::checkPort() – check for available service

Synopsis

require_once 'Net/Portscan.php';

boolean Net_Portscan::checkPort ( string $host , integer $port , integer $timeout = 30 )

Description

This function checks if there is a service available at the specified port on the specified machine.

Parameter

Return value

boolean - Returns TRUE on success, FALSE on failure.

Note

This function can be called statically.

Example

Using checkPort

<?php
require_once "Net_Portscan/Portscan.php";

if (Net_Portscan::checkPort("localhost", 80) == NET_PORTSCAN_SERVICE_FOUND) {
    echo "There is a service on localhost on port 80 (" . Net_Portscan::getService(80) . ").\n";
}
?>

Net_Portscan::checkPortRange()

Net_Portscan::checkPortRange() – check for available services

Synopsis

require_once 'Net/Portscan.php';

array Net_Portscan::checkPortRange ( string $host , integer $minPort , integer $maxPort , integer $timeout = 30 )

Description

This function checks if there are services available at the specified ports on the specified machine.

Parameter

Return value

array - An associative array containing the scanning results for each port.

Note

This function can be called statically.

Example

Using checkPortRange

<?php
require_once "Net_Portscan/Portscan.php";

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 "A service has been found on port " . $port . ".\n";
    } else {
        echo "No service has been found on port " . $port . ".\n";
    }
}
?>

Net_Portscan::getPort()

Net_Portscan::getPort() – port number of a service

Synopsis

require_once 'Net/Portscan.php';

integer Net_Portscan::getPort ( string $service , string $protocol = 'tcp' )

Description

This function returns the port which corresponds to service for the specified protocol as per /etc/services.

Parameter

Return value

integer - port number of the service

Note

This function can be called statically.

The port number is retrieved from the machine where Net_Portscan is executed, not from the remote host, which you possibly used in Net_Portscan::checkPort().

Net_Portscan::getService()

Net_Portscan::getService() – name of the service

Synopsis

require_once 'Net/Portscan.php';

string Net_Portscan::checkPortRange ( integer $port , string $protocol = 'tcp' )

Description

This function returns the service associated with port for the specified protocol as per '/etc/services'.

Parameter

Return value

string - name of service running on the port

Note

This function can be called statically.

The name of the service is retrieved from the machine where Net_Portscan is executed, not from the remote host, which you possibly used in Net_Portscan::checkPort().