Author Topic: IpLookUp tool coded in python.  (Read 1350 times)

0 Members and 1 Guest are viewing this topic.

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
IpLookUp tool coded in python.
« on: 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:


Code: [Select]
#! /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:
Code: [Select]
./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.
« Last Edit: April 13, 2013, 09:56:27 am by proxx »
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline ba203

  • NULL
  • Posts: 4
  • Cookies: -1
    • View Profile
Re: IpLookUp tool coded in python.
« Reply #1 on: November 03, 2012, 12:48:16 am »
Wow!

Offline IFailStuff

  • VIP
  • Knight
  • *
  • Posts: 338
  • Cookies: 25
  • Certified fuckup
    • View Profile
Re: IpLookUp tool coded in python.
« Reply #2 on: November 03, 2012, 12:57:16 am »
Drop the 1337 speak mr.c0de>.<


nice tool ;)

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: IpLookUp tool coded in python.
« Reply #3 on: November 03, 2012, 04:11:51 am »
Thanks guys :)

Btw its totally dependency free :)
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: IpLookUp tool coded in python.
« Reply #4 on: November 03, 2012, 09:19:05 am »
Not bad. Moved to Scripting Languages.