It’s an easy to get the IP address for a domain name using PHP’s gethostbyname() and gethostbynamel() functions. Here in this post looks at some examples of using the gethostbyname() function in PHP to get a single IP address for a hostname.
Example domains used
Examples in this post use www.cnn.com and www.electrictoolbox.com. At the time of the writing of this post, www.cnn.com resolves to 4 possible IP addresses as follows:
The PHP function gethostbyname() is very simple to use. Simply pass it the domain name you would like to look up and it will either return the IP address for that domain or the unmodified domain back again if it failed. If the domain has more than one IP address associated with it (as with www.cnn.com) then just a single IP address will be passed back.
Note that not being able to find an IP address for the domain does not mean the domain does not exist, or even that a record does not exist for this (sub)domain. The DNS lookup may simply have failed.
The PHP gethostbynamel() function returns a list of IP addresses for a domain and I will look at some examples of using this function on Monday.
सयौ थुङ्गा फूलका हामी एउटै माला नेपाली, Welcome to my webpage. I'm from the Himalayan Country of Nepal. Well talking about me, I like mostly Web programming and Designing and furthermore I like Philosophical literature, Photography, Social networking. And I am Romantic and Sentimental person to some extent. Read more...