Duccio
Duccio

Reputation: 9

check domain configuration in a server in php

How can check if a domain name (ex. fqdn.example) is configurated in a server with ip xx.xx.xx.xx?

I have to check that the domain fqdn.example is correctly configured on the server with a given IP.

In php I know the dns_get_record function but it allows me to check only the current DNS zone, not to see if a domain is not registered yet is already configured on the server where it is to reside.

NB. For security reasons I don't want to execute shell commands from php.

Upvotes: 0

Views: 521

Answers (1)

jman
jman

Reputation: 11586

This can be accomplished with gethostbynamel() if the DNS is configured:

<?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");
}
?>

If the domain isn't configured in DNS but you want to see if your web-server is configured, you can try sending a HTTP request of the form

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

to port 80 on that IP address. If you don't get an error, the webserver is configured correctly for that FQDN.

Update:

To query a custom DNS server as per your comment, use Net_DNS.

Upvotes: 1

Related Questions