$whois abc.com
I want to use python to hit this command, and then give the result as a String of text. How can I do that?
$whois abc.com
I want to use python to hit this command, and then give the result as a String of text. How can I do that?
You can use subprocess, for example:
from subprocess import Popen, PIPE
output = Popen(["/usr/bin/whois", "abc.com"], stdout = PIPE).communicate()[0]
The stdout = PIPE
parameter forces stdout to be written to a temporary pipe instead of the console (if you don't want that, remove the stdout
parameter).
subprocess is fine. On the other hand, the whois protocol is so simple that I do not see why to use an external command (and depend on its availability). Just open a TCP connection to port 43, send a one-line query and read the responses.