Monday, May 13, 2013

Explain how to get the DNS servers of a domain name.


<?
function get_dns($domain)
{
     $end = substr("$domain",-2);
     if($end==uk)
         {$type=uk;}
     else
         {$type=com;}
     if($type==uk)
          {$lookup="whois.nic.uk";}
     else{$lookup="rs.internic.net";}
         $fp = fsockopen( "$lookup", 43, &$errno, &$errstr, 10);
         fputs($fp, "$domain\r\n");
     while(!feof($fp))
     {
         $buf = fgets($fp,128);
         if (ereg( "Domain servers", $buf))
         {
              {$dns = fgets($fp,128);}
              {$dns .= fgets($fp,128);}
          }
          if (ereg( "Name Server:", $buf))
         {
              {$dns = fgets($fp,128);}
              {$dns .= fgets($fp,128);}
              $dns = str_replace( "Name Server:", "", $buf);
              $dns = str_replace( "Server:", "", $dns);
              $dns = trim($dns);
          }
      }
      Return $dns;
}
?>
The process is :
- Include the Net/DNS.php file in the beginning of the script 
- Create the object for DNS resolver by using $ndr = Net_DNS_Resolver() 
- Query the ip address using $ndr->search(“somesite.com”,”A”) and assign to a relevant variable. Ex: $result
- Display the value of $result

No comments:

Post a Comment