• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • getservbyname()

    (PHP 4, PHP 5, PHP 7)

    获取互联网服务协议对应的端口

    说明

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

    getservbyname()返回互联网服务$service指定的协议$protocol中对应的端口,依据/etc/services

    参数

    $service

    互联网服务名称的字符串。

    $protocol

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

    返回值

    返回端口号,如果$service$protocol未找到返回FALSE

    范例

    Example #1getservbyname()例子

    <?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";
    }
    ?>
    

    参见

    • getservbyport()Get Internet service which corresponds to port and protocol
    • » http://www.iana.org/assignments/port-numbers端口号的完整列表