php 建议查询DNS解析状态工具

<?php

$num = $_GET['num'];
if($num == ''){$num = 0;}
//站群域名解析状态查询工具

$error_all = $_GET['error_all'];
$success_all = $_GET['success_all'];

if($success_all == ''){
    $success_all=0;
}
if($error_all == ''){
    $error_all=0;
}
//获取域名列表
$file_array = file("list.txt");
//二级域名前缀
$sub_domains = array('www','m','v','news','static');

$success = 0;
$error = 0;
$file = $file_array[$num];

if($file != ''){
    //获取主域名
    $domain = explode(":",$file);
    $domain = trim($domain[0]);
    //查询主域名状态
    if( http_status($domain) == 200){
        $matches = null;
        $html = file_get_contents("http://$domain");
        preg_match('/<title>(.*)<\/title>/s',$html, $matches);
        echo "【$domain => $matches[1]】<br>";
        $success++;
        $success_all++;
    }else{
        echo "<font color='red'>$domain => 主域名检测失败/请检查!</font><br>";
        $error++;
        $error_all;
        
        $error_domains = fopen("error.txt",'a');
        fwrite($error_domains,$domain."\n");
        fclose($error_domains);
    }
    //查询子域名
    for($k=0;$k<sizeof($sub_domains);$k++){
        $matches = null;
        $domain_ = $sub_domains[$k].".".$domain;
        if( http_status($domain_) == 200){
            $html = file_get_contents("http://$domain_");
            preg_match('/<title>(.*)<\/title>/s',$html, $matches);
            echo $domain_." => ".$matches[1]."<br>";
            $success++;
            $success_all++;
        }else{
            echo "<font color='red'>$domain_ => 检测失败/请检查!</font><br>";
            $error++;
            $error_all;
            
            $error_domains = fopen("error.txt",'a');
            fwrite($error_domains,$domain."\n");
            fclose($error_domains);
        }
    }
    
    echo "<br>===============================================================<br>";


echo "<div style='margin-bottom: 20px;text-align:center;background: #c6dfc099;color:#be2ae6; padding: 30px;width: 100%;'><h2>【{$domain}】</h2><h1>当前成功:【".$success."】 === 当前失败:【".$error."】</h1></div>";

echo "<div style='color: green;padding: 30px;text-align:center;background: #c6dfc099;    width: 100%;'><h1>一共成功:【".$success_all."】 === 一共失败:【".$error_all."】</h1></div>";
$num++;
echo "<script>window.location.href='http://104.227.29.146/domains_query_dns/zhanqun_query_dns.php?num=$num&error_all=$error_all&success_all=$success_all'</script>";
}else{
    echo "<h1>程序执行结束</h1>";
    exit();
}
function http_status($url){

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_exec($ch);
$status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $status; 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值