これの前に「もう1人の初心者」というテキストを付けます。Popenコマンドを介してwhoisコマンドの結果が得られた場合、それが適切かどうかをどのようにテストしますか?
通常、Pythonがその長さをテストできるもののリストを返す場合、通常はそれで十分ですが、これはもう少し恣意的です。
たとえば、ドメインの原産国をテストしていますが、gethostbyaddrが提供するドメインがWHOISサーバーによって認識されない場合があります。だから、失敗した場合はIPを送信するつもりだったのですが、70文字以上のテストで終わりました。誰かがこれを行うための「標準的な」方法が何であるかを知っているかどうか疑問に思っています。
w = Popen(['whois', domain], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
whois_result = w.communicate()[0]
print len(whois_result)
if len(whois_result) <= 70:
w = Popen(['whois', p_ip], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
whois_result = w.communicate()[0]
print len(whois_result)
if len(whois_result) <= 70:
print "complete and utter whois failure, its you isnt it, not me."
test = re.search("country.+([A-Z].)",whois_result)
countryid = test.group(1)