如何检查域名列表中是否有站点


How to check if a list of domain names have a site?

我有一大堆abcde.com形式的域名

我要做的是检查域名是否有页面,否则我会得到服务器未找到的消息。

什么是代码,将自动检查这一点,并返回我的东西,如果有一个网站?我熟悉PHP。

谢谢。

简单点就是:

foreach ($domains as $domain) {
    $html =  file_get_contents('http://'.$domain);
    if ($html) {
        //do something with data
    } else {
       // page not found
    }
}

如果你有一个txt文件,每行包含域名,你可以这样做:

$file_handle = fopen("mydomains.txt", "r");
    while (!feof($file_handle)) {
        $domain = fgets($file_handle);
        //use code above here
    }
}
fclose($file_handle);

您可以使用cURL连接到每个域/主机名。

的例子:

// I'm assuming one domain per line
$h = fopen("domains.txt", "r");
while (($host = preg_replace("/['n'r]/", "", fgets($h))) !== false) {
    $ch = curl_init($host);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    if (curl_exec($ch) !== false) {
        // code for domain/host with website
    } else {
        // code for domain/host without website
    }
    curl_close($ch);
}