Using Getservbyname()

 
<?php
    $service = "ftp";
    $port = getservbyname($service, 'tcp');
    if($port === false) {        die("Lookup of service '$service' failed.\n");
    } else {
        echo "Service '$service' runs on port $port\n";
    }
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.