【问题标题】:How to make ping website ip using PHP? [duplicate]如何使用 PHP 制作 ping 网站 ip? [复制]
【发布时间】:2013-06-20 09:41:08
【问题描述】:

我正在编写一个小型 php 脚本,我想在脚本中添加 ping 功能。我真的不知道该怎么做,但是,我喜欢得到与此相同的结果:http://www.ipfingerprints.com/ping.php

【问题讨论】:

    标签: ping


    【解决方案1】:

    根据 php 中的权限,您也许可以

    <?php system("ping -c 3 localhost"); ?>
    

    从网络表单中接受主机名时要非常小心 - 如果用户请求您 ping 服务器“;rm -rf /”,您将丢失所有数据!

    【讨论】:

    • 但我想将结果作为 ipfingerprints 的表格获得
    【解决方案2】:

    很简单

    <?php
    
    if (!$socket = @fsockopen("YOUR.IP.HERE", 80, $errno, $errstr, 30))
    {
      echo "<font color='red'><strong>Offline!</strong></font>";
    }
       else 
        {
      echo "<font color='green'><strong>Online!/strong></font>";
    
      fclose($socket);
    }
    
    ?>
    

    【讨论】:

    • 我想得到结果不是看网站是在线还是离线
    【解决方案3】:

    或在 PHP 中使用此代码“exec('ping -c '.$pingTimes.'.$ipAdress);”

    【讨论】:

      【解决方案4】:

      如果你想要真正的 ping(发送 ICMP 数据包)你可以看看这个Native-PHP ICMP ping implementation,但我没有测试它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-12
        • 1970-01-01
        • 1970-01-01
        • 2011-06-01
        • 2012-09-14
        • 2014-09-13
        相关资源
        最近更新 更多