Gethostbyname function to get IP name of a domain

We can get the ip address of the host server by using the domain name. For example we want to know the ip address of We can use the PHP function gethostbyname(). This function takes the domain name as input and return the dot formatted IPv4 address. Note that this function will contact DNS server so available network must be healthy at the time of running of the script. Let us try the function first.

$result = gethostbyname('');
echo $result;
This is the ip address of the host server of


Now from this information we can find out the domain name by using another function gethostbyaddr(). This function will take ip address as input and return the domain name. Let us add the above two functions and see what happens if out put of one function is used as input to other. Here is the code.

$result = gethostbyname('');
echo $result;
echo "<br>";
echo gethostbyaddr($result);
The output of the above code is


This function gives us more information. It returns an array with all the details. To display this array we will use print_r function. Here is the code.
$result = gethostbynamel('');
The output of above code is here
Array ( [0] => [1] => [2] => )

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here .

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 All rights reserved worldwide Privacy Policy Disclaimer