Search code examples
phpdnsgethostbyname

DNS Lookup: Get IP Address From DNS/Host Name


I need to get the IP address of a domain by the domain name.

  1. Site: hotmail.com / 65.55.72.151
  2. Site: domain.com / 65.254.244.180

Can it be done, and in that case, how can I do it?


Solution

  • You can use this code:

    <?php
    $ip = gethostbyname('www.site.com');
    
    echo $ip;
    ?>
    

    Or, you could operate it dynamically...

    <?php
    $url = $_GET['url'];
    $ip = gethostbyname($url);
    
    echo $ip;
    ?>