PHP/DNS/DNS Functions

Материал из Web эксперт
Перейти к: навигация, поиск

DNS Lookup Functions

   <source lang="html4strict">

Name Description gethostbyname() Gets IP address corresponding to the hostname gethostbynamel() Gets list of IP addresses corresponding to the hostname gethostbyaddr() Gets hostname corresponding to an IP address getmxrr() Fetches the mail exchange (MX) record associated with a hostname dns_get_mx() Alias for getmxrr() checkdnsrr() Checks for the existence of DNS records for a hostname dns_check_record() Alias for checkdnsrr() dns_get_record() Fetches DNS records associated with a hostname <?php $ip = gethostbyname("www.example.ru"); echo "IP = $ip\n"; $host = gethostbyaddr("192.0.34.166"); echo "Host = $host\n"; $ip = gethostbynamel("yahoo.ru"); print_r($ip); ?>

 </source>
   
  


DNS Record Types and Their Meanings

   <source lang="html4strict">

A Address code, used for storing an IP address associated with the domain

MX Mail exchange, the domain name used for sending and receiving mail

NS The authoritative name server

SOA Start of Authority

PTR Domain name pointer

CNAME Canonical name for a DNS alias

AAAA Address code used for IPv6 Addresses

ANY Any of the above

 </source>
   
  


Fetches DNS records associated with a hostname

   <source lang="html4strict">

<?php $record = dns_get_record("php.net"); print_r($record); ?>

 </source>
   
  


Performing DNS Lookups

   <source lang="html4strict">

gethostbyname() gets IP address corresponding to the hostname gethostbynamel() gets list of IP addresses corresponding to the hostname gethostbyaddr() gets hostname corresponding to an IP address getmxrr() fetches the mail exchange (MX) record associated with a hostname dns_get_mx() alias for getmxrr() checkdnsrr() checks for the existence of DNS records for a hostname dns_check_record() alias for checkdnsrr() dns_get_record() fetches DNS records associated with a hostname <?php $ip = gethostbyname ( "www.wbex.ru" ); echo "IP = $ip\n"; $host = gethostbyaddr ( "192.0.34.166" ); echo "Host = $host\n"; $ip = gethostbynamel ( "yahoo.ru" ); print_r ( $ip ); ?>

 </source>
   
  


Using the dns_check_record() Function

   <source lang="html4strict">

<?php

   $hostname = "google.ru";
   if(dns_check_record($hostname, "NS")) {
       echo "An authoritative name server exists.\n";
   } else {
       echo "No name server was found for this domain\n";
   }

?>

 </source>