EvilZone

Programming and Scripting => Scripting Languages => : proxx October 16, 2012, 10:44:28 AM

: IpLookUp tool coded in python.
: proxx October 16, 2012, 10:44:28 AM
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/ZW1nriqx



Output:
:
./ipaddress.com_lookup 12.12.12.12

################################
 ##############################
  #   Ip@ddress.com   Tool  #
 ##############################
############proxx################

[Working be patient]


[@]  Coordinates:(64.8378,-147.7164);

[@]  Organization:Alascom

[@]  ISP:AT&amp;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.
: Re: IpLookUp tool coded in python.
: ba203 November 03, 2012, 12:48:16 AM
Wow!
: Re: IpLookUp tool coded in python.
: IFailStuff November 03, 2012, 12:57:16 AM
Drop the 1337 speak mr.c0de>.<


nice tool ;)
: Re: IpLookUp tool coded in python.
: proxx November 03, 2012, 04:11:51 AM
Thanks guys :)

Btw its totally dependency free :)
: Re: IpLookUp tool coded in python.
: Kulverstukas November 03, 2012, 09:19:05 AM
Not bad. Moved to Scripting Languages.