目前我监视我的网站的IPv4和IPv6地址以编程方式监视每个IP的一个URL
但我的下一个网站将托管多个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;
}
?>
我怎么能拿的所有IP地址,卷曲PHP测试?
我想怎么办就与此类似简单的版本:
<?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);
}
谢谢,但它对我们更好e dns_get_record($ host,DNS_AAAA);我更新了我的问题,并改为标题 – chriscatfr
对不起,不知道我是否真的明白你的问题... – doublesharp
这只是我真的不喜欢使用exec()。我甚至禁用了我的Web服务器上的所有类似功能 – chriscatfr