Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Python way would you suggest to check whois database records?

I'm trying to get a webservice up and running that actually requires to check whois databases. What I'm doing right now is ugly and I'd like to avoid it as much as I can: I call gwhois command and parse its output. Ugly.

I did some search to try to find a pythonic way to do this task. Generally I got quite much nothing - this old discussion list link has a way to check if domain exist. Quite not what I was looking for... But still, it was best anwser Google gave me - everything else is just a bunch of unanwsered questions.

Any of you have succeeded to get some method up and running? I'd very much appreciate some tips, or should I just do it the opensource-way, sit down and code something by myself? :)

like image 683
kender Avatar asked Sep 08 '08 18:09

kender


2 Answers

Look at this: http://code.google.com/p/pywhois/

pywhois - Python module for retrieving WHOIS information of domains

Goal: - Create a simple importable Python module which will produce parsed WHOIS data for a given domain. - Able to extract data for all the popular TLDs (com, org, net, ...) - Query a WHOIS server directly instead of going through an intermediate web service like many others do. - Works with Python 2.4+ and no external dependencies

Example:

>>> import pywhois
>>> w = pywhois.whois('google.com')
>>> w.expiration_date
['14-sep-2011']
>>> w.emails
['[email protected]',
 '[email protected]',
 '[email protected]',
 '[email protected]']
>>> print w
...
like image 118
Aziz Avatar answered Nov 15 '22 21:11

Aziz


Found this question in the process of my own search for a python whois library.

Don't know that I agree with cdleary's answer that using a library that wraps a command is always the best way to go - but I can see his reasons why he said this.

Pro: cmd-line whois handles all the hard work (socket calls, parsing, etc)

Con: not portable; module may not work depending on underlying whois command. Slower, since running a command and most likely shell in addition to whois command. Affected if not UNIX (Windows), different UNIX, older UNIX, or older whois command

I am looking for a whois module that can handle whois IP lookups and I am not interested in coding my own whois client.

Here are the modules that I (lightly) tried out and more information about it:

pywhoisapi:

  • Home: http://code.google.com/p/pywhoisapi/
  • Design: REST client accessing ARIN whois REST service
  • Pros: Able to handle IP address lookups
  • Cons: Able to pull information from whois servers of other RIRs?

BulkWhois

  • Home: http://pypi.python.org/pypi/BulkWhois/0.2.1
  • Design: telnet client accessing whois telnet query interface from RIR(?)
  • Pros: Able to handle IP address lookups
  • Cons: Able to pull information from whois servers of other RIRs?

pywhois:

  • Home: http://code.google.com/p/pywhois/
  • Design: REST client accessing RRID whois services
  • Pros: Accessses many RRIDs; has python 3.x branch
  • Cons: does not seem to handle IP address lookups

python-whois:

  • Home: http://code.google.com/p/python-whois/
  • Design: wraps "whois" command
  • Cons: does not seem to handle IP address lookups

whoisclient - fork of python-whois

  • Home: http://gitorious.org/python-whois
  • Design: wraps "whois" command
  • Depends on: IPy.py
  • Cons: does not seem to handle IP address lookups

Update: I ended up using pywhoisapi for the reverse IP lookups that I was doing

like image 22
Lars Nordin Avatar answered Nov 15 '22 20:11

Lars Nordin