#!/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.1 *" print "*Coded by Laramies *" 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) < 2: usage() sys.exit() host=sys.argv[1] cmd=sys.argv[1] banner() body="ips="+host print "\nSearching in Maxmind....\n" try: h = httplib.HTTP("www.maxmind.com") h.putrequest('POST',"/app/locate_ip" ) h.putheader('content-type',"application/x-www-form-urlencoded") h.putheader('content-length', str(len(body))) h.endheaders() h.send(body) errcode, errmsg, headers = h.getreply() response=h.file.read() limit=re.compile("reached.*") if limit.findall(response)!=[]: print "Limit reached in maxmind :(\n" else: res=re.compile(".*") 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: "+res[0] 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 "\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" 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] except: print "Connection error..\n"