Geolocation error with IP address 127.0.0.1

OK, so I tried implementing this, http://ipaddressextensions.codeplex.com/.

It is displaying the output as:-

127.0.0.1 RESERVED ZZ

What on earth is this “RESERVED” and “ZZ”? It should be displayed as “INDIA IN”.

The IP address is of the local host. All right, but what about the country name and country code? Why won’t they display correctly? What do I need to change in my code?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

127.0.0.1 is a reserved IP address which stands for localhost (the computer that the code is running on). This is a “valid” IP address for every computer that runs TCP/IP.

IP lookups need a real IP address in order to work correctly.

In regards to the country code – it is probably a 2 character country ISO code (see here), so you need to translate the code to the correct country. ZZ is not in the table, signifying no country.

Method 2

127.0.0.1 is known as the loopback address and is what your system uses to talk to itself effectively. As a result, there is no country associated with that IP address… it’s everywhere on every system.

If you put your code out onto the web you’d get more appropriate results as each visiting system would be using a public IP address to reach your server.

Method 3

When you are testing from home, both server and user are one (your PC). So you can’t expect it to show the country as the IP address for IIS is a self address.

Your code seems to be fine. Also you can use a free ASP.NET supporting host to try your website online. There are many like HelioHost, 0000free, etc.

Regarding the edit part of your question, if you are using different versions of the site for each country then wouldn’t be using a switch better.

switch(iso3166TwoLetterCode.ToUpper())
{
    case "IN" : Response.Redirect("www.mysite.in");
    case "FR" : Response.Redirect("www.mysite.fr");
    ...
    Default : Response.Redirect("www.mysite.in");
}

I think it does look neater.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x