Prefacing this with the text 'just another beginner'. when you have the result of a whois command via the Popen command, how do you test if its good ?
Normally when Python returns a list of whatever you can test the length of it and that has usually sufficed for me, but this is a little more arbitrary.
eg im testing for a domains country of origin, but sometimes the domains that gethostbyaddr gives me are not recognised by the WHOIS server. So, i thought i would go with sending it an ip in case of failure but I've ended up with this not so pretty less than 70 characters test. Just wondering if anyone knows what the 'standard' way of doing this is.
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)