Computer-Masters.net > Articles > Programming > PHP > PHP: Get IP address of a domain

PHP: Get IP address of a domain or URL

With just a single statement it is possible to find out the IP address of a domain or URL.

 

Simply use the gethostbyname() function in PHP to get the IP address.

See the example below to find out how to use this function.

You find the output of the code below the code.


PHP-Script

<?php
$domain 
"Computer-Masters.net";

$ip gethostbyname($domain);

echo 
"Domain: ".$domain;
echo 
"<br>";
echo 
"IP: ".$ip;
?>
1

 

The output of the code is the following:

Domain: Computer-Masters.net
IP: 109.237.138.34

 

 

You can also simply use this form to get the IP of a hostname:

Get IP of a URL

IP: 109.237.138.34

Host: Computer-Masters.net

Further Information

These articles might also be interesting for you:

 

You still have questions?

Feel free to use our comment form that is also available for non-registered users.

The Terms of Use and Posting Guidelines apply.

 

Comments

Computer-Masters.net > Articles > Programming > PHP > PHP: Get IP address of a domain

Advertisement: