getservbyname

(PHP 4, PHP 5, PHP 7, PHP 8)

getservbyname獲取互聯(lián)網(wǎng)服務(wù)協(xié)議對應(yīng)的端口

說明

getservbyname(string $service, string $protocol): int

getservbyname() 返回互聯(lián)網(wǎng)服務(wù) service 指定的協(xié)議 protocol 中對應(yīng)的端口, 依據(jù) /etc/services

參數(shù)

service

互聯(lián)網(wǎng)服務(wù)名稱的字符串。

protocol

protocol 既可以是 "tcp" 也可以是 "udp" (小寫)。

返回值

返回端口號,如果 serviceprotocol 未找到返回 false。

范例

示例 #1 getservbyname() 例子

<?php
$services 
= array('http''ftp''ssh''telnet''imap',
'smtp''nicname''gopher''finger''pop3''www');

foreach (
$services as $service) {
    
$port getservbyname($service'tcp');
    echo 
$service ": " $port "<br />\n";
}
?>

參見