Python Geolocation with GeoIP2

Python Geolocation with GeoIP2

                                      Geolocation with GeoIP 2

               IP geolocation is the mapping of an IP address to the geographic location of the internet from the connected device. By geographically mapping the IP address, it provides you with location information such as the country, state, city, zip code, latitude/longitude.

API Reference:

                   The GeoIP object does not require any parameters to use the default settings. However, at the very least the GEOIP_PATH setting should be set with the path of the location of your GeoIP datasets.

Keyword Arguments:

 * Path:
                 Base directory to where GeoIP data is located or the full path to where the city or country data files (.mmdb) are located. Assumes that both the city and country datasets are located in this directory; overrides the GEOIP_PATH setting.

 * Cache:
              The cache settings when opening up the GeoIP datasets. May be an integer in (0, 1, 2, 4, 8) corresponding to the MODE_AUTO, MODE_MMAP_EXT, MODE_MMAP, and GEOIP_INDEX_CACHE MODE_MEMORY C API settings, respectively. Defaults to 0 (MODE_AUTO).

 * Country:
             The name of the GeoIP country data file. Defaults to GeoLite2-Country.mmdb. Setting this keyword overrides the GEOIP_COUNTRY setting.

 * City:
          The name of the GeoIP city data file. Defaults to GeoLite2-City.mmdb. Setting this keyword overrides the GEOIP_CITY setting.



                              classmethod, cache)

Returns a dictionary of city information for the given query. Some of the values in the dictionary may be undefined (None).
Returns a dictionary with the country code and country for the given query.

Returns the country code corresponding to the query.

Returns the country name corresponding to the query.

Coordinate Retrieval:

Returns a coordinate tuple of (longitude, latitude).

Returns a coordinate tuple of (longitude, latitude).

Returns a coordinate tuple of (latitude, longitude),

Returns a Point object corresponding to the query.

Which database to use?

Overall, all geolocation databases have room to improve their router geolocation accuracy at both country- and city-level. Researchers and network operators need to be aware of inaccuracies and their impact on their results.

That said, if you intend to use one of the geolocation databases we tested, here are our recommendations:

 we recommend using this to geolocate routers if using a geolocation database is the only available option. NetAcuity has the best combination of coverage and accuracy across all regions.
 we recommend using the commercial version of MaxMind over the public version if city-level accuracy and better coverage are required. That said, we don't recommend MaxMind databases if high city-level accuracy and coverage are required the city-level accuracy is especially bad in the ARIN region, however, we do see relatively good city-level results for MaxMind in the RIPE NCC and APNIC regions.

IP2Location-Lite - we don't recommend this service given the overall accuracy is too low.

More Articles of Bhanu Prakash Reddy M:

Name Views Likes
Python Geolocation with GeoIP2 1191 61
Python Geoip2 Modules 1237 34
Python Geoip Enriching MMDB files 1088 16
Python Geoip2 Configuring geolocation 1160 24
Python Random Module 1039 22
Python GeoIP2 Precision Services 1065 24
GeoIP - MaxMind GeoIP2 API 1566 21
Python Generate secure random numbers 1055 41
Python - Generic output formatting 716 11
Python - Prims minimum spanning tree 807 22
Python Program for Choosing Balls 1367 17
Python - Dijkstras shortest path algorithm 1452 24
Python Cryptographic Secure hashes and message digests 1168 65
Python program for Smallest Palindrome 1822 13
Python program for Friends on Facebook 1253 21
Python Cryptographic Generating tokens 975 13
Python - Cookies in CGI 1608 23
Python - Stream Encoding and Decoding 999 16
Python program for frequency is a function that takes as input a list of integers and returns a pair of the form (minfreqlist,maxfreqlist) 1682 42
Python - Stateless Encoding and Decoding in Binary data service 821 22
Python Binary Data Services 789 92
Python CGI Environment Variables 864 20
Python GeoIP2 JavaScript Client API 1103 33
Python - CGI Programming 629 39
Python program for panagram 1364 30
Plotting Series in Python 1273 24
GeoIP in PYTHON 1358 23
Python Concrete exceptions 1140 12
Python Geoip Maxmind 1206 34
Python Random module --2 939 18
Python-- Programs 1176 14
Python Types of Anonymous IPs and How They Affect Your Business 1049 19
Python Cryptographic Introduction 991 11
Geoip-IP geolocation information in Python. 1241 15
Python Geoip Database Reader Exceptions 1185 30
Python Data Changes to GeoIP Legacy 972 10
Python - Binary Data Services - 2 721 33
Python Program for Rotate Matrix Elements 1141 11
Python Program post-order traversal of a tree without using recursion 902 22
Python Program In-order traversal of a tree without using recursion 1151 28
Python MaxMind GeoIP2 1312 33
Python The Easy Way to Use MaxMind GeoIP 1546 25
Python Program 1277 20
Python GeoIP2 Databases with HAProxy Enterprise 1053 25
Python The Knights tour problem 1790 47
Python User-defined Exceptions 897 57
Python Program pre-order traversal of a tree without using recursion 1019 29
Python - Standard Encodings in Binary Data service 753 29
Python Binary Data Service Error Handlers 696 51
Python program for Domino Solitaire 2005 22
Python Built-in Exceptions 938 13
CGI Programming-2 860 49
GeoIP -- Flask. 1368 15
Python IP Geolocation 1018 13
Python Concrete exceptions part-2 1329 28