int getservbyname ( string $service , string $protocol )
(PHP 4, PHP 5)

이 함수는 서비스 이름과 전송 프로토콜로 포트번호를 반환하는 함수입니다. $protocol에 TCP 또는 UDP로 포트번호를 반환받을 수 있습니다.

유닉스에는 서비스와 포트번호가 "/etc/services"에 저장되고, 프로토콜은 "/etc/protocol"에 저장됩니다.

<?php
 echo getservbyname('http', 'tcp'); // http 포트는 보통 80입니다.
 /*
 결과:
 80
 */
 ?>

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

 foreach ($services as $serv) {
    $port = getservbyname($serv, 'tcp');
    echo $serv . ": " . $port . "<br />\n";
 }

 /*
 결과:
 http: 80
 ftp: 21
 ssh: 
 telnet: 23
 imap: 143
 smtp: 25
 nicname: 43
 gopher: 70
 finger: 79
 pop3: 110
 */
 ?>

0 댓글