0 Usuarios y 1 Visitante están viendo este tema.

*

D3M0N

  • Founder
  • Usuario
  • *****
  • 3.034
Geolocalizaciín de una IP
07 de Septiembre de 2011, 07:59:53 pm

Un script que me encontrí por cierto foro programado en Python, para geolocalizar una IP. Solo copiamos el siguiente cídigo y lo guardamos como "geoedge.py"


Código: [Seleccionar]
#!/usr/bin/env python
#Geoedge v0.1
#Coded by laramies
#cmartorella@edge-security.com
#Remember that maxmind allows just 25 queries per day. Don't abuse ;)

import sys
import re
import httplib

def banner():
print "*************************************"
print "*Geoedge v0.2 *"
print "*Coded by Christian Martorella *"
print "*cmartorella@edge-security.com *"
print "*************************************"

def usage():
banner()
print "\n"
print "Usage:"
print " python geoedge.py host/ip\n"
return

if len(sys.argv) < host="sys.argv[1]" cmd="sys.argv[1]" body="ips=" h =" httplib.HTTP(" headers =" h.getreply()" response="h.file.read()" limit="re.compile(" res="re.compile(" style="">.*")
results=res.findall(response)
res=[]
for x in results:
x=x.replace("","")
x=x.replace("","")
res.append(x)

print "Information for "+host+ " by Maxmind"
print "===========================================\n"
print "IP/Host: "+host
country=re.sub("<.*nk>\">","",res[1])
country2=country.replace("","")
country=re.sub("<.*middle\" >","",country2)
print "Country: " +country +","+res[2]
print "City: " + res[4] +","+res[5]
print "Coordinates: "+ res[7] + "," + res[8]
print "Provider: "+ res[9] + "," + res[10]
print "Google Maps Link: " + "http://maps.google.com/maps?q="+res[7]+", "+res[8]
print "Mapquest Link: " + "http://www.mapquest.es/mq/maps/latlong.do?pageId=latlong&latLongType=decimal&txtLatitude="+res[7]+"&txtLongitude="+res[8]
print "\n"
except:
print "Connection error...\n"

print "Searching in Geoiptool....\n"
try:

h = httplib.HTTP("www.geoiptool.com")
h.putrequest('GET',"/es/?IP="+host )
h.putheader('Host', 'www.geoiptool.com')
h.putheader('User-agent', 'Internet Explorer 6.0 ')
h.endheaders()
returncode, returnmsg, headers = h.getreply()
response=h.file.read()

res=re.compile(".*")
results=res.findall(response)
res=[]

for x in results:
x=x.replace("","")
x=x.replace("","")
res.append(x)

print "Information by Geoiptool"
print "========================\n"
print "IP/Host: "+res[0]
country=re.sub("<.*nk\">","",res[1])
country=country.replace("","")
country=re.sub("<.*middle\" >","",country)
print "Country: " + country + ","+ res[2]
city=re.sub("<.*nk\">","",res[3])
city=city.replace("","")
print "City: " + city + ","+ res[4]
print "Coordinates: " + res[8] + ","+res[7]
print "\n"
except:
print "Connection error..\n"

La sintaxis de uso es la siguiente:

Código: [Seleccionar]
python geoedge.py google.com
En donde google.com es el host o la IP.