douan4359 2016-06-06 01:39
浏览 30
已采纳

检查ip6是否已关闭

I'm trying to check if ip6 is not connected in my code using php. My idea now is to calculate the loading if it is going to connect. I try to use this code.

$file = file_get_contents('http://ip6.me/');

// Trim IP based on HTML formatting
$pos = strpos( $file, '+3' ) + 3;
$ip = substr( $file, $pos, strlen( $file ) );

// Trim IP based on HTML formatting
$pos = strpos( $ip, '</' );
$ip = substr( $ip, 0, $pos );
$ipaddress = $ip;
$ip_get = explode('.',$ipaddress);

this work fine with me if will get ip address. But there is a time that ip6 down and it load to much. What is the best way to check if ip6 is down? I try to calculate the load of browser, but I have no idea how to do it.

  • 写回答

2条回答 默认 最新

  • duandao7704 2016-06-06 04:36
    关注

    I would ping a server over IPv6. On linux, you can use the following code.

    exec('ping -6 -c 1 2001:4860:4860::8888', $lines, $exit); // ping will return 0 if ping succeeds
    if($exit == 0) {
        // up
        echo "up
    ";
    } else {
        //down
        echo "down
    ";
    }
    

    EDIT:

    Samuel's answer tests whether a TCP port is reachable over IPv6. In some cases, because of firewall configuration, only one of the methods may work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用