在php中检查服务器中的域配置


check domain configuration in a server in php

如何检查域名(例如fqdn.example)是否在具有ip xx.xx.xx.xx的服务器中配置?

我必须检查域fqdn.example是否在具有给定IP的服务器上正确配置。

在php中,我知道dns_get_record函数,但它只允许我检查当前的DNS区域,而不是查看域是否尚未注册,是否已在其所在的服务器上配置。

注:。出于安全原因,我不想从php执行shell命令。

如果配置了DNS,则可以使用gethostbyname()实现:

<?php
$hostname = "fqdn.example";
$key = "198.51.100.100";
$ips = gethostbynamel($hostname);
if (array_search ($key, $ips) != FALSE) {
    echo ("$hostname configured at $key");
}
else {
    echo ("$hostname not configured at $key");
}
?>

如果域名没有在DNS中配置,但你想看看你的网络服务器是否配置好了,你可以尝试发送形式的HTTP请求

GET / HTTP/1.1
host: fqdn.example
Connection: Close

到该IP地址上的端口80。如果没有收到错误,则说明已为该FQDN正确配置了Web服务器。

更新:

要根据您的评论查询自定义DNS服务器,请使用Net_DNS。