开发者

Net_Ping with port number. How?

So there are a number of ways to ping an address but I have had good luck with the net Ping library in PHP. The only problem is, I cannot for the life of me figure out how to ping a port number on a host. I know it has to be something silly.

I have tried host:port with no luck. I would really like to stick with Net Ping because the outpu开发者_运维知识库t is very usable.

Here's my example code.

<?php
    require_once "Net/Ping.php";

    $ping = Net_Ping::factory();


    if(PEAR::isError($ping))
      echo $ping->getMessage();
    else
    {
      /* Number of packets to send */
      $ping->setArgs(array('count' => 4));
      $rawData = $ping->ping('example.com');
      print_r($rawData);
    }
?>


A ping is not based on ports, it is an ICMP command. The concept of a port just doesn't make sense to ICMP. If you're going to be doing a port based ping, you need something on the other side of the connection at that port to answer to you - for example a server_status.php page that returns "OK". In this case, you would be doing an HTTP "ping", not a real ping but just a web request - but you can collect quite a bit of data from it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜