What Python Way Would You Suggest To Check Whois Database Records?
Solution 1:
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
['contact-admin@google.com',
'dns-admin@google.com',
'dns-admin@google.com',
'dns-admin@google.com']
>>>print w...
Solution 2:
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
Solution 3:
There's nothing wrong with using a command line utility to do what you want. If you put a nice wrapper around the service, you can implement the internals however you want! For example:
classWhois(object):
_whois_by_query_cache = {}
def__init__(self, query):
"""Initializes the instance variables to defaults. See :meth:`lookup`
for details on how to submit the query."""
self.query = query
self.domain = None# ... other fields.deflookup(self):
"""Submits the `whois` query and stores results internally."""# ... implementation
Now, whether or not you roll your own using urllib, wrap around a command line utility (like you're doing), or import a third party library and use that (like you're saying), this interface stays the same.
This approach is generally not considered ugly at all -- sometimes command utilities do what you want and you should be able to leverage them. If speed ends up being a bottleneck, your abstraction makes the process of switching to a native Python implementation transparent to your client code.
Practicality beats purity -- that's what's Pythonic. :)
Solution 4:
Here is the whois client re-implemented in Python: http://code.activestate.com/recipes/577364-whois-client/
Solution 5:
I don't know if gwhois does something special with the server output; however, you can plainly connect to the whois server on port whois (43), send your query, read all the data in the reply and parse them. To make life a little easier, you could use the telnetlib.Telnet class (even if the whois protocol is much simpler than the telnet protocol) instead of plain sockets.
The tricky parts:
- which whois server will you ask? RIPE, ARIN, APNIC, LACNIC, AFRINIC, JPNIC, VERIO etc LACNIC could be a useful fallback, since they tend to reply with useful data to requests outside of their domain.
- what are the exact options and arguments for each whois server? some offer help, others don't. In general, plain domain names work without any special options.
Post a Comment for "What Python Way Would You Suggest To Check Whois Database Records?"