geo-lite database
2- load it all into memory
3- make a b tree out of all the ranges available.
4- now you have an ip in your own database that want to know which country it belongs to right? So, lookup that IP in the b tree you create. Whichever range it matched on. Lookup the country for that range.
Now you know which country a given IP belongs to.
You can do whatever you want with that information in your original database
Looks good I want t know which countries have most IPs in my database
Same thing. Only you need some sort of map. You will lookup each ip in the b tree Then creat a map like {"Iran": 1} If you find another user form iran do Users["iran"] +1
What language are you using for your project? geoip-lite might be available for your language.
Takes tooo long 😐 if user needs to use online mode takes more time
No it doesn't you're doing something that it just happens that I have done before. If you load geoip-lite into memory it takes up to 15sec but it's a one time cost. Then lookups are really fast in b tree. Like I'm talking 9ms response.
I use that feature in index page :D
What are you exactly trying to do?
I've a table in my db that contains some IP addresses I'm wanting to show top 6 countries to users
I see, and you want to update this in real time?
Yes And will refreshed by user
Обсуждают сегодня