Prefix WhoIs in Python


Part of a project I’m into requires me to dig for some details on IP addresses. Normal whois query (default to whois.apnic.net) don’t give me the information that I really need for, and upon searching I came to the Prefix Whois Project. They have came up with whob, and from the website I get to know that I can even get part of whob‘s functionality by just to query for whois from their server. Let’s try with our favorite’s TMNut Screamyx DNS

 

shakir@herugrim ~ $ whois -h whois.pwhois.org 202.188.0.133
IP: 202.188.0.133
Origin-AS: 4788
Prefix: 202.188.0.0/19
AS-Path: 6079 4788
AS-Org-Name:
Org-Name: Asia Pacific Network Information Centre
Net-Name: APNIC-CIDR-BLK
Cache-Date: 1195082506
Latitude: 3.167000
Longitude: 101.700000
City: -
Region: -
Country: MALAYSIA

I’ve just started to learn, and like Python, and let’s see my Python example to extract the whois info;

import commands

def main():

    whoisServer = "whois.pwhois.org"
    IPAddr = "202.188.0.133"

    status, output = commands.getstatusoutput('whois -h ' + whoisServer + " " + IPAddr)

    result = {}

    for i in output.splitlines():
        stripped = i.split(':')
        result[stripped[0]] = stripped[1]

    print result

if __name__ == "__main__":
    main()


Tags: , ,

Leave a Reply

Advertisement