sukhjit dhot
sukhjit dhot

Reputation: 353

How to know domain name from IP address in PHP

As we know about PHP has an inbuilt function to get IP address of a domain name

<?php
$ip = gethostbyname('www.example.com');

echo $ip;
?>

But is there any way to know domain name from Ip address?

I have tried using gethostbyaddr but it din't worked.

<?php echo gethostbyaddr( '198.252.206.16' ); ?>

I think there should be some way of using the command dig in combination with PHP in Linux but I am not sure.

Upvotes: 2

Views: 1607

Answers (3)

A.J.
A.J.

Reputation: 1530

If you have shell access, Unix/Linux servers can use this for a timeout response:

shell_exec('host -W 2 0.0.0.0');

Where 0.0.0.0 is of course the IP, and '2' is the number of seconds for the timeout. This returns a more detailed string of info, with some additional text which might vary depending on the system, so if you want a string with the hostname and nothing else, you'll have to do some substring cutting.

Try this.

Upvotes: 0

RoelAdriaans
RoelAdriaans

Reputation: 803

You can get the A adress of that server. If there are multiple websites on that webserver you do not get that information

Upvotes: 1

Basil Basaif
Basil Basaif

Reputation: 372

Try using a valid IP address. I tried going to the IP address that you provided, but nothing was there.

Upvotes: 0

Related Questions