Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically monitor every IP for one URL
    primarykey
    data
    text
    <p>Currently I monitor my websites on their IPv4 and IPv6 addresses</p> <p>But my next website will be hosted with multiple IP Addresses. And I would like to <strong><em>monitor ALL of them</em></strong>.</p> <p>Here is my current code for dual-stack monitoring (monitoring only one IP address)</p> <pre><code>&lt;?php $resultat4 = file_get_contents_curl( 'http://www.mydomain.com/?cjg_monitoring=1', 4); $resultat6 = file_get_contents_curl( 'http://www.mydomain.com/?cjg_monitoring=1', 6); if (substr($resultat4,0,2) == "OK"){ echo 'IPv4 stack OK' } if (substr($resultat6,0,2) == "OK"){ echo 'IPv6 stack OK' } function file_get_contents_curl($url,$ip_version=0) { $ch = curl_init(); if($ip_version == 4) curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); elseif($ip_version == 6) curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6 ); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } ?&gt; </code></pre> <p>How could I get all the IP addresses tested with Curl PHP ?</p> <p>What I would like to do would be similar to this simpler version:</p> <pre><code>&lt;?php $ip_adds = get_all_ip_addresses( $url ); $problem_encountered = false; foreach( $ip_adds as $ip_add ){ $content = get_content_url_on_ip( 'http://www.mydomain.com/?cjg_monitoring=1', $ip_add ); if ( $content != "OK") $problem_encountered = true; } if ( !$problem_encountered ) echo "All IPv4 and IPv6 Addresses OK"; ?&gt; </code></pre> <p>in my case www.mydomain.com has many ip addresses of each version:</p> <pre><code>$host www.mydomain.com www.mydomain.com has address 173.194.35.180 www.mydomain.com has address 173.194.35.176 www.mydomain.com has address 173.194.35.177 www.mydomain.com has IPv6 address 2001:db8:4016:801::1008 www.mydomain.com has IPv6 address 2001:db8:4016:801::1009 www.mydomain.com has IPv6 address 2001:db8:4016:801::1010 </code></pre> <p>Which is why I use this :</p> <pre><code> //return array[0][ip] or array[0][ipv6] function get_all_ip_addresses( $url ){ $url_tab = parse_url($url); $host = $url_tab['host'] $ip4s = dns_get_record($host, DNS_A); $ip6s = dns_get_record($host, DNS_AAAA); return array_merge($ip4s, $ip6s); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload