Catch user city with IP

Asked

Viewed 4,140 times

5

I need to take the city that the user is in at the time of access to the Control Panel of the Site.

'Cause I need this?

I’m willing to block access to the control panel only for my client’s city, when he doesn’t have IP fixed, if he has, I lock access only to his fixed IP.

I’ve tested the GEOIP, but it gives me a very large distance, for example:

I put my IP and he showed me a town 50 miles from where I am.

Someone knows how to do it?

2 answers

3

  • I’ll take a look to see how it works. Thanks for the time being

  • I took a look and to register says I have to have an "IP server", I believe it should be a fixed ip, thing I do not own, so I think I will not be able to register and test :( correct me if I’m wrong, please.

  • This geoplugin was one of the ones I tested and returned me a city more than 50 km away from where I am.. and the ipinfo, returned me that I am in Porto Alegre.. that gives about 40 km of my city...

  • Sorry, I don’t have enough knowledge to collect IP very accurately, I don’t know if it’s easy to find a service like this. I recommend a better study on this, try on Google so "ip Location with Precision", in English is better because it has more possibility to have better information. If you know something, share it here later. = ) Good luck!

2

Link: http://ip-api.com/json

Documentation: http://ip-api.com/docs/api:json

Example:

{
  "status": "success",
  "country": "United States",
  "countryCode": "US",
  "region": "CA",
  "regionName": "California",
  "city": "San Francisco",
  "zip": "94105",
  "lat": "37.7898",
  "lon": "-122.3942",
  "timezone": "America/Los_Angeles",
  "isp": "Wikimedia Foundation",
  "org": "Wikimedia Foundation",
  "as": "AS14907 Wikimedia US network",
  "query": "208.80.152.201"
}
  • This appeared to me: { "as":"AS8167 Brasil Telecom S/A - Filial Distrito Federal", "city":"Sapiranga", "country":"Brazil", "countryCode":"BR", "isp":"Oi Internet", "lat":-29.6333,"Lon":-51, "org":"Oi Internet", "query:"189.74.216.34", "Region":"RS", "Name": "Rio Grande do Sul", "status":"Success", "Timezone":"America/Sao_paulo", "zip":"" } Sapiranga is about 25 km from my city.. And I need to be exact, I don’t think I will.. I’m already thinking of another way but I haven’t found a better answer yet..

  • I believe that it also depends a lot on external factors, such as DNS, and the operators' servers. Sometimes with me in Google itself shows the city where the ISP is, IE, about 200km away, other times appears correctly the city where I am depending on the network.

  • 1

    I understand, but for the purpose I need I can not take the risk of the customer being in the city and not be able to access the Control Panel of the Site because at the time he was logged in appeared that he was in a city 30 km from where he is :). but I am checking the possibility of when to log in, send an email with a hash for authentication, like a token, but I am still analyzing the possibility, but thanks for the help.

  • Interestingly, in fact I didn’t think of this possibility either, blocking by region is complicated, even more talking about cloud computing as it is today that can be accessed anywhere. Something like two steps could be done, like Google uses. Have you thought about?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.