getservbyport与getservbyname函数如何在php中使用

getservbyport与getservbyname函数如何在php中使用?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

具体如下:

string getservbyport ( int $port , string $protocol ) 
 
*/ 
$services=array('80','21','22','23','25','143');      //定义数组 
foreach($services as $service)         //循环读取内容 
{ 
  $protocol=getservbyport($service,'tcp');       //返回端口号对应的协议 
  echo $service.":".$protocol."<br/>n";       //输出结果 
} 
 
/* 
int getservbyname ( string $service , string $protocol ) 
*/ 
 
$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与getservbyname函数如何在php中使用问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。