Get ip address and name servers of a domain name using PHP


Published January 3, 2013 at 2:13 PM

The problem

How to keep track of my domains without having to manually update them. Specifically get the ip address so I can see where I'm hosting it and the name servers to see where I'm controlling the DNS.

The Solution (in PHP)

$domain = "";

 $dnsA = dns_get_record($domain, DNS_A);
    foreach($dnsA as $key=>$value){
  echo $value['ip'].'<br />';

 $dnsNS = dns_get_record($domain, DNS_NS);
    foreach($dnsNS as $key=>$value){
  echo $value['target'].'<br />';