python pygeoip example
from flask import Flask, request, jsonify
import pygeoip, json
app = Flask(__name__)
geo = pygeoip.GeoIP('GeoLiteCity.dat', pygeoip.MEMORY_CACHE)
@app.route('/')
def index():
client_ip = request.remote_addr
geo_data = geo.record_by_addr(client_ip)
return json.dumps(geo_data, indent=2) + '\n'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80, debug=False)