php中 getservbyport getservbyname函数实例

  1. string getservbyport ( int $port , string $protocol )
  2. */
  3. $services=array('80','21','22','23','25','143'); //定义数组
  4. foreach($services as $service) //循环读取内容
  5. {
  6. $protocol=getservbyport($service,'tcp'); //返回端口号对应的协议
  7. echo $service.":".$protocol."<br/>n"; //输出结果
  8. }
  9. /*
  10. int getservbyname ( string $service , string $protocol )
  11. */
  12. $services=array('http','ftp','ssh','telnet','imap',
  13. 'smtp','nicname','gopher','finger','pop3','www'); //定义一个数组
  14. foreach($services as $service) //循环读取内容
  15. {
  16. $port=getservbyname($service,'tcp'); //获取数组元素对应端口
  17. echo $service.":".$port."<br/>n"; //输出结果
  18. //开源代码phpfensi.com
  19. }