<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Admon Home &#187; whois</title>
	<atom:link href="http://www.admon.org/tag/whois/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.admon.org</link>
	<description>Linux System Administration</description>
	<lastBuildDate>Wed, 08 Feb 2012 10:24:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Query domain name whois info by Python</title>
		<link>http://www.admon.org/query-domain-name-whois-info-by-python/</link>
		<comments>http://www.admon.org/query-domain-name-whois-info-by-python/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 06:21:58 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[whois]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=890</guid>
		<description><![CDATA[In one of our former post, we give an example on how to query IP whois info by Python, here is an example on how to query whois information for a domain name. #!/usr/bin/python #encoding = utf8 #Author:hysia import sys import socket PORT = 43 WhoisServers = {'com':'whois.internic.net', 'net':'whois.internic.net', 'org':'whois.pir.org', 'nfo':'whois.afilias.info', 'biz':'whois.biz', '.cc':'whois.nic.cc', 'edu':'rs.internic.net', 'mil':'whois.nic.mil', [...]]]></description>
			<content:encoded><![CDATA[<p>In one of our former post, we give an example on how to <a title="Query IP whois info" href="http://planet.admon.org/query-ip-whois-info-in-python/" target="_blank">query IP whois info by Python</a>, here is an example on how to query whois information for a domain name.</p>
<pre>#!/usr/bin/python
#encoding = utf8<span id="more-890"></span>
#Author:hysia

import sys
import socket

PORT  =  43
WhoisServers = {'com':'whois.internic.net',
              'net':'whois.internic.net',
              'org':'whois.pir.org',
              'nfo':'whois.afilias.info',
              'biz':'whois.biz',
              '.cc':'whois.nic.cc',
              'edu':'rs.internic.net',
              'mil':'whois.nic.mil',
              'gov':'whois.nic.gov',
              '.uk':'whois.nic.uk',
              '.us':'whois.nic.us',
              'ame':'whois.nic.name',
              'eum':'whois.museum',
              '.su':'whois.ripn.net',
              '.ru':'whois.nic.ru',
              'int':'whois.iana.org',
              '.ws':'whois.worldsite.ws',
              '.kr':'whois.krnic.net',
              '.jp':'whois.nic.ad.jp',
              '.it':'whois.nic.it',
              '.de':'whois.denic.de',
              '.fr':'whois.nic.fr',
              '.ca':'whois.cira.ca',
              '.cn':'whois.cnnic.net.cn',
              '.tw':'whois.twnic.net.tw',
              '.hk':'whois.hkdnr.net.hk',
              '.au':'whois.aunic.net',
              '.ac':'whois.nic.ac',
              'DEF':'whois.verisign-grs.com'}
              #'DEF':'whois.apin.net'}

fulldomain = sys.argv[1]

if fulldomain.startswith('www.'):
    fulldomain = fulldomain[4:]

domain = fulldomain[-3:]
print 'Domain: ',fulldomain
if not WhoisServers.get(domain):
    whoisserver = WhoisServers['DEF']
else:
    whoisserver = WhoisServers[domain]
print whoisserver

try:
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.connect((whoisserver,PORT))
    s.send(fulldomain + "\r\n")
    response = ''

    while True:
        data = s.recv(4096)
        response += data
        if data == '':
            break
    s.close()
    infomation = response.lower()
    try:
        pos = infomation.find('expiration date: ')
        expirDate = infomation[pos+17:pos+28]
        print 'Expiration Date:',expirDate
    except:
        print 'unkown'

except:
    print 'time out'
</pre>
<p>Looks smart! But never mind that the whois info cannot be returned correctly sometimes. I haven&#8217;t got time to look into this limitation.<br />
The script is copied from here: <a rel="external" href="http://blog.hysia.com/2010/03/25/python-whois.html">http://blog.hysia.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/query-domain-name-whois-info-by-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Query IP whois info in python</title>
		<link>http://www.admon.org/query-ip-whois-info-in-python/</link>
		<comments>http://www.admon.org/query-ip-whois-info-in-python/#comments</comments>
		<pubDate>Tue, 18 Jan 2005 05:38:41 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[whois]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=528</guid>
		<description><![CDATA[This is a simple python script  based on some former rwhois code. It shows us an easy way on how to get detailed information about a specific IP address: joseph@e54:~$ python ip-whois.py 94.75.214.11 ====== whois.arin.net OrgName: RIPE Network Coordination Centre OrgID: RIPE Address: P.O. Box 10096 City: Amsterdam StateProv: PostalCode: 1001EB Country: NL ReferralServer: whois://whois.ripe.net:43 [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple python script  based on some former <a href="http://sourceforge.net/projects/rwhois/files/">rwhois</a> code. It shows us an easy way on how to get detailed information about a specific IP address:</p>
<pre>joseph@e54:~$ python <strong>ip-whois.py</strong> 94.75.214.11
====== whois.arin.net                        

OrgName:    RIPE Network Coordination Centre
OrgID:      RIPE
Address:    P.O. Box 10096<span id="more-528"></span>
City:       Amsterdam
StateProv:
PostalCode: 1001EB
Country:    NL

ReferralServer: whois://whois.ripe.net:43

NetRange:   94.0.0.0 - 94.255.255.255
CIDR:       94.0.0.0/8
NetName:    94-RIPE
NetHandle:  NET-94-0-0-0-1
Parent:
NetType:    Allocated to RIPE NCC
NameServer: NS-PRI.RIPE.NET
NameServer: SEC1.APNIC.NET
NameServer: SEC3.APNIC.NET
NameServer: TINNIE.ARIN.NET
NameServer: NS2.LACNIC.NET
Comment:    These addresses have been further assigned to users in
Comment:    the RIPE NCC region. Contact information can be found in
Comment:    the RIPE database at http://www.ripe.net/whois
RegDate:    2007-07-30
Updated:    2009-05-18</pre>
<p>The source code is listed below. You may copy the code into a text file and name it as <em>ip-query.py</em>:</p>
<pre>#!/usr/bin/env python
# Forwarded version from <a href="http://thomasfischer.biz/posts/ip-whois-query-via-python">thomasfischer.biz</a>!!!
#
import os, sys, string, time, getopt, socket, select, re, errno, copy, signal        

def queryWhois(query, server='whois.ripe.net'):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    while 1:
        try:
            s.connect((server, 43))
        except socket.error, (ecode, reason):
            if ecode==errno.EINPROGRESS:
                continue
            elif ecode==errno.EALREADY:
                continue
            else:
                raise socket.error, (ecode, reason)
            pass
        break                                            

    ret = select.select ([s], [s], [], 30)

    if len(ret[1])== 0 and len(ret[0]) == 0:
        s.close()
        raise TimedOut, "on data"           

    s.setblocking(1)

    s.send("%sn" % query)
    page = ""
    while 1:
        data = s.recv(8196)
        if not data: break
        page = page + data
        pass

    s.close()

    if string.find(page, "IANA-BLK") != -1:
        raise 'no match'

    if string.find(page, "Not allocated by APNIC") != -1:
        raise 'no match'

    return page

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print "usage: %s " % sys.argv[0]
        sys.exit(1)
    ip = sys.argv[1]

    for server in ['whois.arin.net', 'whois.ripe.net', 'whois.apnic.net', 'whois.lacnic.net', 'whois.afrinic.net']:
        try:
            res = queryWhois(ip, server)
            print '======', server
            print res
            break # we only need the info once
        except:
            pass</pre>
<p>If you wanna find whois information about some domain names, you might need to re-write these open-sourced scripts. An suggested alternative choice is <a href="http://code.google.com/p/pywhois/">pywhois which is hosted by code.google.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/query-ip-whois-info-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

