December 2, 2024

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
$domain = "Computer-Masters.net";

$ip = gethostbyname($domain);

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

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:

IP: 109.237.138.34

Host: Computer-Masters.net

Further Information

These articles might also be interesting for you:

Leave a Reply

Your email address will not be published. Required fields are marked *