[字号:  ]

如何用PHP实现Ping命令?

发布时间:2008-10-07 13:19   作者: licess   信息来源: PHPChina 开源社区门户
如何用PHP实现如下Ping命令啊~在CMD下输入ping 97.74.0.31
并返回:

C:\Documents and Settings\Administrator>ping 97.74.0.31

Pinging 97.74.0.31 with 32 bytes of data:

Reply from 97.74.0.31: bytes=32 time=477ms TTL=44
Reply from 97.74.0.31: bytes=32 time=771ms TTL=44
Reply from 97.74.0.31: bytes=32 time=817ms TTL=44
Reply from 97.74.0.31: bytes=32 time=811ms TTL=44

Ping statistics for 97.74.0.31:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 477ms, Maximum = 817ms, Average = 719ms

网上有个类似的网站:
http://www.just-ping.com/
能够输入IP或域名和输出结果,
请各位帮忙~~这个是如何实现的,谢谢了

[ 本帖最后由 licess 于 2008-10-7 13:30 编辑 ]

最新回复

licess at 2008-10-07 14:08:20
~~难道没有人会吗??
Ven at 2008-10-07 14:59:09
PEAR里有个Net_Ping,楼主可以试试看
houhuiyang at 2008-10-07 16:17:11
<?php
    // $cmd = 'C:\WINDOWS\system32\Cmd.exe';
// $last_line = exec($cmd, $state);
  $dns = ' ipconfig /all';
     $last_line = exec($dns, $state);
  echo '<pre>';
     print_r($state);
飘渺晴霜 at 2008-10-07 17:25:33
<?php
  $ping = `ping google.com`;
  echo $ping;
?>

[ 本帖最后由 飘渺晴霜 于 2008-10-7 17:27 编辑 ]
魔·閃光飛鹰 at 2008-10-08 11:06:23
5楼的不错!
qai41 at 2008-10-09 14:24:05
<?php
  $ping = `ping google.com`;
  echo $ping;
?>

太经典了 ,能说说为什么这样可以?
wsleocn at 2008-10-09 15:34:55

QUOTE:

原帖由 qai41 于 2008-10-9 14:24 发表


太经典了 ,能说说为什么这样可以?
你去查查 "``"  执行运算符 就知道了
fansuser at 2008-10-09 15:50:07
五楼的很经典,还可以简写成这样,刚学到的
<?php
  echo `ping google.com`;
?>
hearts-A at 2008-10-09 15:51:34
貌似这个书上都有的啊....``...用这个符号就行了...
licess at 2008-10-09 17:31:07
呵呵,谢谢各位~