2

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.

sukhjit dhot
  • 353
  • 2
  • 5
  • 18
  • 1
    What is your definition of "it didn't work"? –  Dec 28 '13 at 21:05
  • I am not sure, but look up for this function : `checkdnsrr();` – Shahlin Ibrahim Dec 28 '13 at 21:06
  • 1
    The same IP is used in an example in the manual (doesn't work because there are unicode characters in the domain name). In the same manual there are solutions via `exec` and using said `dig` command - so did you research this at all? – kero Dec 28 '13 at 21:07
  • yes i did it i am trying to figure out from past couple of hours . tried everything to make it work but no success. – sukhjit dhot Dec 28 '13 at 21:11
  • You can always use whois or try to use CURL and 'visit' that page and get info about it – breq Dec 28 '13 at 21:20

3 Answers3

1

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

RoelAdriaans
  • 763
  • 7
  • 16
0

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

Basil Basaif
  • 362
  • 8
  • 20
  • using stackoverflow ip now – sukhjit dhot Dec 28 '13 at 21:15
  • Using the stackoverflow.com IP worked using `gethostbyaddr`, it returns the domain. I tried using the same code with my website but it returned something different. Is it working for you? or do u still have the same problem? – Basil Basaif Dec 28 '13 at 21:19
0

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.

A.J.
  • 1,520
  • 17
  • 22