fix some things :3

master
Felix Pankratz 1 year ago
parent cd763f3930
commit 7f6b5dda21

62
ip.py

@ -1,31 +1,31 @@
#!/usr/bin/env python #!/usr/bin/env python
import cgi import cgi
import os import os
import pygeoip import pygeoip
def header(): def header():
print("Content-type: text/plain") print("Content-type: text/plain")
print("") print("")
def main(): def main():
params = cgi.FieldStorage() params = cgi.FieldStorage()
out = { out = {
"ip": None, "ip": None,
"country": None, "country": None,
"continent": None, "continent": None,
"location": None "location": None
} }
header() header()
client_ip = cgi.escape(os.environ["REMOTE_ADDR"]) client_ip = os.environ["REMOTE_ADDR"]
format = F_PLAIN if(len(params) > 0):
if(len(params) > 0): for key in params:
for key in params: if key == "geo":
if key == "geo": gi = pygeoip.GeoIP('GeoLiteCity.dat')
gi = pygeoip.GeoIP('GeoLiteCity.dat') geo_info = gi.record_by_addr(client_ip)
geo_info = gi.record_by_addr(ip) geo_info['ip'] = client_ip
print(geo_info) print(geo_info)
else: else:
print(client_ip) print(client_ip)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

Loading…
Cancel
Save