getservbyport
GETS the Internet service which corresponds to
port and
protocol.
<?php
str|false getservbyport ( int $port , str $protocol )
where,
$port = The port number
$protocol = The protocol tcp or udp
( lowercase )
?>
$port
The port number.
$protocol
The protocol lowercase name tcp or udp.
Transmission Control Protocol (TCP)
Is one of the main protocols of the Internet protocol suite.
It originated in the initial network implementation in which it complemented the Internet Protocol,(IP).
Therefore, the entire suite is commonly referred to as TCP/IP.
TCP provides reliable, ordered, and error-checked delivery of a stream of octets, (bytes), between applications running on hosts communicating via an IP network.
Major internet applications such as the World Wide Web, email, remote administration, and file transfer rely on TCP.
User Datagram Protocol (UDP) Is one of the core members of the Internet protocol suite.
The protocol was designed by David P. Reed in 1980 and formally defined in
RFC 768.
User Datagram Protocol
With
UDP, computer applications can send messages, in this case referred to as datagrams, to other hosts on an
Internet Protocol,(IP) network.
EXERCISE
<table width="100%" cellspacing="3" cellpadding="3"
border="1" align="center"><tbody><tr><td colspan="2">SOME tcp SERVICES</td>
</tr><tr><td >PORT</td><td>PROTOCOL</td></tr>
<?php
$port01 = [80, 81, 21, 22, 23, 143, 25, 43, 70, 79, 110, 443];
foreach ($port01 as $prt01) { ?>
</tr><td><?php echo $prt01; ?></td>
<td><?php echo getservbyport($prt01, 'tcp'); ?></td></tr>
<?php } ?>
</tr>
<tr><td colspan="2">ed48</td></tr></tbody></table>
RESULT SOME tcp SERVICES |
PORT | PROTOCOL |
80 | http |
81 | hosts2-ns |
21 | ftp |
22 | ssh |
23 | telnet |
143 | imap |
25 | smtp |
43 | nicname |
70 | gopher |
79 | finger |
110 | pop3 |
443 | https |
ed48 |
EXERCISE
<table width="100%" cellspacing="3" cellpadding="3"
border="1" align="center"><tbody><tr><td colspan="2">tcp SERVICES</td>
</tr><tr><td>PORT</td><td >PROTOCOL</td></tr>
<?php
for ($prt03 = 1; $prt03 <= 10000; $prt03++)
{ if(getservbyport($prt03, 'tcp')) { ?>
</tr><td><?php echo $prt03; ?></td><td><?php echo getservbyport($prt03, 'tcp'); ?></td></tr>
<?php } } ?>
</tr><tr><td colspan="2">ed48</td></tr></tbody></table>
EXERCISE
<table width="100%" cellspacing="3" cellpadding="3"
border="1" align="center"><tbody><tr><td colspan="2">udp SERVICES</td></tr>
<tr><td>PORT</td><td>PROTOCOL</td></tr>
<?php
for ($prt02 = 1; $prt02 <= 10000; $prt02++)
{ if(getservbyport($prt02, 'udp')) { ?>
</tr><td><?php echo $prt02; ?></td>
<td><?php echo getservbyport($prt02, 'udp'); ?></td></tr>
<?php } } ?>
</tr><tr><td colspan="2">ed48</td></tr></tbody></table>