get host name by IP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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('') returns:

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

Quoted text here. Click to load it

I think this does what you want:

Re: get host name by IP

Alojzy Majchrzak wrote:
Quoted text here. Click to load it

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: /


Site Timeline