首页 > 语言 > PHP > 正文

php中 getservbyport getservbyname函数实例

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表