tags:

views:

81

answers:

2

I try to get whois in python. I use this http://code.google.com/p/pywhois/ but it run only in linux. Is it posible to run it on windows? currently i get errors (because internal linux command whois used)

+1  A: 

You could use :

os.system("whois %s" % hostname)

Or use urllib to connect http://www.whois.net and scrap content.

Guillaume Lebourgeois
Please us `subprocess.Popen` instead of `os.system`
S.Lott
@Guillaume, your first suggestion (with `subprocess`, not `os.system`) is exactly what `pywhois` uses (on any OS -- see my A with a single line quoted from pywhois's sources), with nice post-processing for parsing the results and making them more usable. You just need a `whois` installed and correctly working -- if your first suggestion works, so will `pywhois`!-)
Alex Martelli
@S.Lott Why not, but could you explain why ?
Guillaume Lebourgeois
@Guillaume Lebourgeois: http://www.python.org/dev/peps/pep-0324/ "The subprocess module provides the following enhancements over previous functions:" Summary: `subprocess.Popen` is better than `os.system`
S.Lott
+2  A: 

On Windows just like on Linux, pywhois gives an error if the whois program is not installed. You could try this whois, for example.

The reason, of course, is in pywhois/init.py, line 11:

r = subprocess.Popen(['whois', domain], stdout=subprocess.PIPE)

Clearly this line needs to run some existing, installed whois command-line program (which accepts the domain to look up as a commandline argument), whatever OS it's running on.

Alex Martelli
thnx Alex! it works!
Evg