A little while a go I coded a little tool to refresh my memory.
I wanted to be able to do quick lookups on specific addresses and not having to maintain a large databse nor do tedious clicking work.
So I wrote a little CLI tool to do it for me.
It queries ipaddress.com's database and regex matches some stuff, nothing special.
Its poorly coded probably buggy but it works.
Source c0de:
#! /usr/bin/env python2
import socket
import re
import sys
print """
################################
##############################
# Ip@ddress.com Tool #
##############################
############proxx################
"""
for arg in sys.argv:
IP = arg
print "[Working be patient]"
print "\n"
HOST = IP + '.ipaddress.com'
PORT = 80
GET='/'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
connection = s.makefile('r',0)
s.send("GET %s HTTP/2.0\r\nHost: %s\r\n\r\n" % (GET, HOST))
buff = connection.readlines()
raw_data = []
for line in buff:
#print line + "\n\n"
raw_data.append(line)
s.close()
del raw_data[5]
clean_data = []
for i in raw_data:
if "this IP:" in i :
clean_data.append(i)
if "Organization:"in i :
clean_data.append(i)
if "ISP:" in i :
clean_data.append(i)
if "Country:" in i :
clean_data.append(i)
if "City:" in i :
clean_data.append(i)
if "State:" in i:
clean_data.append(i)
if "Timezone:" in i :
clean_data.append(i)
if "Local Time:" in i:
clean_data.append(i)
if "var coord=new google.maps.LatLng(" in i:
clean_data.append("Coordinates:"+i)
del clean_data[2]
del clean_data[1]
for i in clean_data:
i = i.lstrip ("<tr><th>")
i = i.rstrip ("</td></tr>")
new = re.sub('</th><td class="sep"></td><td>', "", i)
new2 = re.sub('</td></tr>', "", new)
new3 = re.sub('" style="vertical-align:baseline">', "", new2)
new4 = re.sub('var coord=new google.maps.LatLng', '', new3)
new5 = re.sub('<img src="/flags/?>', '', new4)
new5 = new5.strip("<img src=\"/flags/")
new5 = new5.strip("<img")
new6 = re.sub('<img?', '', new5)
new7 = re.sub('src="/flags/?', '', new6)
new8 = re.sub('...gif" alt=""', '', new7)
new9 = re.sub('title.\=*?.?.?.?.?.?.?.?.?\s.?....?.?.?.?..?.?.?.?', '', new8)
print "[@] "+new9
In case the indention fucks up;
http://pastebin.com/ZW1nriqxOutput:
./ipaddress.com_lookup 12.12.12.12
################################
##############################
# Ip@ddress.com Tool #
##############################
############proxx################
[Working be patient]
[@] Coordinates:(64.8378,-147.7164);
[@] Organization:Alascom
[@] ISP:AT&T Services
[@] City:Fairbanks
[@] Country:United States
[@] State:Alaska
[@] Timezone:America/Anchorage
[@] Local Time:16.10.2012 00:43:51
Burn me down , thank me or say nothing
Im new here so maybe i got it all wrong.