With the PyGeoIP package you can capture geo location data, which is pretty cool, for example, when you have IOT devices pushing location data to elasticsearch and visualizing the data with Kibana. That will be one example, but the possibilites are endless.
Dependencies:
Get the Maxmind Geo Database:
1 2 |
|
Install Python Flask and PyGeoIP:
1
|
|
Getting Started with PyGeoIP:
Let’s run through a couple of examples on how to get:
- Country Name by IP Address and DNS
- Country Code by IP Address and DNS
- GeoData by IP Address
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
Python Flask Web App to Capture Data
Let’s create a basic Flask App that will capture the data from the client making the request to the server. In this example we will just return the data, but we can filter the data and ingest it into a database like elasticsearch, etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Run the Server:
1
|
|
Make a request from the client over a remote connection:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|