Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- get host name by IP
- Alojzy Majchrzak
June 5, 2009, 9:18 pm
rate this thread
I`ve used such code to know what country IP represents:
$domain='PL' -> POLAND
$domain='DE' -> GERMANY
Everything works fine when IP address is changed into NAME DOMAIN
I have a IP address:
which doesn`t have NAME DOMAIN representative and
gethostbyaddr('188.8.131.52') returns: 184.108.40.206.
Can you tell me how to change the above code to get the country from this
I add that this IP is from Germany and it is mobile phone internet
Please help me because I cannot find any example on internet
Thank you in advance for help
Re: get host name by IP
That way does not work at all. A server can have any number of domains
assigned to it and they usually have, because they host pages for many
different customers. And of course every domain can be from a different
country and none of them have to be the one where the server actually
On top of that, some IPs (most notably end users) do not get a hostname
assigned to their IPs at all as you have already seen.
The only (at least somewhat) reliable way to know which IP belongs to
which country is to use a database which holds the current assignment of
IP ranges to countries.
These reason why these databases are not perfectly reliable are pretty
obvious: There may be errors in the database or the assignments may have
changed after the database was last updatet. On top of that it is
usually difficult to find out if a user is using a proxy, in which case
you will get the country where the proxy resides, not the user.
You can download a good database here:
- » a function to output multiple variable names, getting the name of a var into a string,
- — Next thread in » PHP Scripting Forum