Menu Home

getservbyport

osbo.com | PHP | Functions | getservbyport

Get Internet service which corresponds to port and protocol

Syntax

getservbyport ( int $port , string $protocol ) : string

Parameters

port

The port number.

protocol

protocol is either "tcp" or "udp" (in lowercase).

Return

Returns the Internet service name as a string.

Examples

port protocol

<?

$port = 80;
$protocol = "tcp";

$return = getservbyport($port, $protocol);

echo $return;

?>
http

1

<?

$array = array(21, 22, 23, 25, 43, 70, 79, 80, 110, 143);
$protocol = "tcp";

foreach ($array as $port)
{
    $return = getservbyport($port, $protocol);

    echo "$port: $return\n";
}

?>
21: ftp
22: ssh
23: telnet
25: smtp
43: nicname
70: gopher
79: finger
80: http
110: pop3
143: imap

PHP