PHP language provides two convenient functions to achieve this.
- gethostbyaddr()
-gethostbyname()
The gethostbyaddr() and gethostbyname() functions will return the hostname or IP address of a given machine, respectively.
The syntax of these function is as follows
gethostbyaddr("IP Address");
gethostbyname("hostname");
- <?php
- // set iP address
- $ip="74.125.224.147";
- // set hostname
- $hostname="www.google.com";
- $resolved_hostname=gethostbyaddr($ipadd);
- $resolved_ip=gethostbyname($hostname);
- echo"The IP address $ip resolves to $resolved_hostname";
- echo"The Hostname $hostname resolves to $resolved_ip";
- ?>