Files: (scopo illustrativo)
GeoIPCity.dat
GeoIP lib python
Output:
GeoIPCity.dat
GeoIP lib python
Codice:
#!/usr/bin/python
import GeoIP
import sys
import os
print "\n\n * Geo IP locator"
print " * Created by ^4st3r1X^"
print " * 02/11/09\n\n"
try:
ip = sys.argv[1]
except:
print " * Utilizzo:\n * /home/percorso/file/location.py [IP]"
print " * Esempio: \n * /home/percorso/file/location.py 82.2.18.1\n\n"
exit()
database = "~/GeoIP/GeoIPCity.dat" #modificare
try:
control = GeoIP.open(database, GeoIP.GEOIP_MEMORY_CACHE)
info = control.record_by_addr(ip)
country_code3 = info['country_code3']
country_name = info['country_name']
city = info['city']
region_name = info['region_name']
postal_code = info['postal_code']
latitude = info['latitude']
longitude = info['longitude']
time_zone = info['time_zone']
except:
print " * Utilizzo:\n * /home/percorso/file/location.py [IP]"
print " * Esempio: \n * /home/percorso/file/location.py 82.2.18.1\n\n"
exit()
if info != None:
print "Sigla Stato: %s" % (country_code3)
print "Nome Stato: %s" % (country_name)
print "Citta': %s" % (city)
print "Regione: %s" % (region_name)
print "Codice Postale: %s" % (postal_code)
print "Latitudine: %s" % (latitude)
print "Longitudine: %s" % (longitude)
print "Fuso orario: %s\n\n\n" % (time_zone)
print "----------"
a = raw_input("Se desideri vedere la posizione geografica sul satellite digita 's' altrimenti premi invio: ")
if a == 's':
link = '"http://maps.google.it/maps?q=%s,%s(Posizione Geografica %s)"' % (latitude, longitude, ip)
os.popen("firefox %s &" % (link))
else:
exit()
Output: