PHP language provides two convenient functions to achieve this.
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
- // set iP address
- $ip = "184.108.40.206";
- // 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";