How to get the Nameservers of a domain using PHP

H

How Can We Help?

How to get the Nameservers of a domain using PHP

Use the  dns_get_record function with type DNS_NS

Example:

//Add this piece of code to your PHP will
$result = dns_get_record(‘yourdomain.com‘,DNS_NS);

Execute the script

//An array will be returned similar as below

Array
(
    [0] => Array
        (
            [host] => yourdomain.com
            [type] => NS
            [target] => ns1.yourdomain.com
            [class] => IN
            [ttl] => 70144
        )

    [1] => Array
        (
            [host] => yourdomain.com
            [type] => NS
            [target] => ns2.yourdomain.com
            [class] => IN
            [ttl] => 70144
        )

)

Explanation:

dns_get_record = Fetch DNS Resource Records associated with a hostname (PHP 5)

About the author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me