This article mainly introduces the usage of the getservbyport and getservbyname functions in php, and analyzes how the getservbyport and getservbyname functions obtain the port information of the server in the form of instances, for more information about getservbyport and getservbyname functions in php, see the following example. Share it with you for your reference. The details are as follows:
The code is as follows:
String getservbyport (int $ port, string $ protocol)
*/
$ Services = array ('80', '21', '22', '23', '25', '123'); // define an array
Foreach ($ services as $ service) // read content cyclically
{
$ Protocol = getservbyport ($ service, 'tcp '); // return the protocol corresponding to the port number.
Echo $ service. ":". $ protocol ."
N "; // output result
}
/*
Int getservbyname (string $ service, string $ protocol)
*/
$ Services = array ('http', 'ftp ', 'Ssh', 'telnet ', 'imap ',
'Smtp ', 'nicname', 'gopher', 'finger ', 'pop3', 'WWW '); // defines an array
Foreach ($ services as $ service) // read content cyclically
{
$ Port = getservbyname ($ service, 'tcp '); // Obtain the port corresponding to the array element
Echo $ service. ":". $ port ."
N "; // output result
}
I hope this article will help you with php programming.