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 - Generic output formatting 360 11
Python - Standard Encodings in Binary Data service 330 29
Python - Stream Encoding and Decoding 379 16
Python - Stateless Encoding and Decoding in Binary data service 355 22
Python Binary Data Service Error Handlers 353 51
Python - Binary Data Services - 2 373 33
Python Binary Data Services 389 92
Python - Dijkstras shortest path algorithm 465 24
Python - Prims minimum spanning tree 403 22
Python - Cookies in CGI 346 23
Python CGI Environment Variables 377 20
CGI Programming-2 389 49
Python - CGI Programming 385 39
Python The Knights tour problem 537 47
Python User-defined Exceptions 626 57
Python Concrete exceptions part-2 630 28
Python Concrete exceptions 617 12
Python Built-in Exceptions 631 13
Python Program In-order traversal of a tree without using recursion 645 28
Python Program pre-order traversal of a tree without using recursion 639 29
Python Program post-order traversal of a tree without using recursion 652 22
Python Cryptographic Generating tokens 709 13
Python Cryptographic Secure hashes and message digests 697 65
Python Cryptographic Introduction 734 11
Python Generate secure random numbers 733 41
Python Random module --2 735 18
Python Random Module 736 22
Python IP Geolocation 754 13
Python Data Changes to GeoIP Legacy 749 10
Python Geoip Enriching MMDB files 758 16
Python The Easy Way to Use MaxMind GeoIP 795 25
Python Types of Anonymous IPs and How They Affect Your Business 774 19
Python GeoIP2 Databases with HAProxy Enterprise 773 25
Python Geoip Maxmind 798 34
Python Geoip2 Configuring geolocation 810 24
Python Geolocation with GeoIP2 808 61
Python GeoIP2 JavaScript Client API 814 33
Python GeoIP2 Precision Services 816 24
Python Geoip2 Modules 880 34
Python Geoip Database Reader Exceptions 880 30
Python MaxMind GeoIP2 863 33
Python program for panagram 891 30
Python program for Smallest Palindrome 916 13
Python program for Friends on Facebook 938 21
Python Program for Choosing Balls 896 17
Python program for frequency is a function that takes as input a list of integers and returns a pair of the form (minfreqlist,maxfreqlist) 928 42
Python Program for Rotate Matrix Elements 895 11
GeoIP -- Flask. 911 15
Geoip-IP geolocation information in Python. 908 15
GeoIP - MaxMind GeoIP2 API 918 21
Python Program 919 20
Python program for Domino Solitaire 924 22
Python-- Programs 910 14
Plotting Series in Python 930 24
GeoIP in PYTHON 964 23