get website ip using php

by Guna 2011-10-18 14:30:27

Hi,

To get an IP of a website in php, generally we use,

gethostbyname("example.com");


This will work nicely, but for some urls instead of returning IP of the given url this function outputs url what you typed. For example, we can try this url "lappusa.com". When try to get this website ip using gethostbyname() function it only outputs "lappusa.com". When you try this website in browser it will redirect you to another website.

The reason is "lappusa.com" doesn't resolve any ip address, so the browser automatically prepends "www" to the url.You can also replicate the same functionality in our code by adding "www" to the url,

gethostbyname("www.example.com");


Now this returns IP of the given website. There is another function in php called "gethostbynamel ()". This function returns an array which consists list of ipv4 addresses of given url. You can get more info in phpmanual about this manual.

Tagged in:

1112
like
0
dislike
0
mail
flag

You must LOGIN to add comments