You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
615 B
Python

#!/usr/bin/env python
import cgi
import os
import pygeoip
def header():
print("Content-type: text/plain")
print("")
def main():
params = cgi.FieldStorage()
header()
client_ip = os.environ["REMOTE_ADDR"]
if(len(params) > 0):
for key in params:
if key == "geo":
import json
gi = pygeoip.GeoIP('GeoLiteCity.dat')
geo_info = gi.record_by_addr(client_ip)
geo_info['ip'] = client_ip
print(json.dumps(geo_info, indent=2))
else:
print(client_ip)
if __name__ == "__main__":
main()