目前我在他们的 IPv4 和 IPv6 地址上监控我的网站
但我的下一个网站将使用多个 IP 地址托管。我想监视所有这些。
这是我当前用于双栈监控的代码(仅监控一个 IP 地址)
<?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;
}
?>
如何获得所有使用 Curl PHP 测试的 IP 地址?
我想做的类似于这个更简单的版本:
<?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";
?>
在我的情况下 www.mydomain.com 有每个版本的许多 IP 地址:
$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
这就是我使用它的原因:
//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);
}