user3818576 user3818576 - 2 years ago 113
PHP Question

check if ip6 is down

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('');

// 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.

Answer Source

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\n";
} else {
    echo "down\n";


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download