PHP/DNS/gethostbynamel

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

Retrieving All IPs Associated with a Domain

   <source lang="html4strict">

<?php

   $hostname = "google.ru";
   $ip_addrs = gethostbynamel($hostname);
   if(!$ip_addrs) {
       echo "Could not resolve the domain name $hostname
\n"; } else { echo "Here is a list of IPs associated with $hostname:

\n\n"; foreach($ip_addrs as $ip) { echo "IP: $ip
\n"; } }

?>

 </source>
   
  


Reverse Lookup of IPs Based on Domain

   <source lang="html4strict">

<?php

   $ip_addr = gethostbyname("www.google.ru");
   if($ip_addr ==="www.google.ru") {
       echo "Could not resolve the IP address for the host!
\n"; } else { echo "The IP address for the host is: $ip_addr
\n"; }

?>

 </source>