如何解决Ubuntu上的WHOIS命令仅返回响应代码?
我正在尝试使用python3和whois command on Ubuntu以编程方式查找whois信息。
例如:
import os
# Set domain
hostname = "google.com"
# Query whois
response = os.system("whois " + hostname)
# Check the response
print("This is the Response:" + str(response))
返回此:
... MarkMonitor Domain Management(TM)保护公司和消费者 在数字世界中。
通过https://www.markmonitor.com访问MarkMonitor,通过以下地址与我们联系 +1.8007459229在欧洲,电话+44.02032062220 -**这是回应:** 0
以退出代码0结束的过程
whois信息按预期方式显示(在引号中看不到),但是响应始终只是退出代码。
我需要退出代码之前的信息。我必须在Whois信息中搜索特定字段。响应= 0时该如何处理?
解决方案:
import subprocess
# Set domain
hostname = "google.com"
# Query whois
response = subprocess.check_output(
"whois {hostname}".format(hostname=hostname),stderr=subprocess.STDOUT,shell=True)
# Check the response
print(response)
如下所述,应使用subprocess.check_output()而不是os.system。
循环时的解决方案:
for domain in domain_list:
hostname = domain
response = subprocess.run(
"whois {hostname}".format(hostname=hostname),shell=True)
# Check the response
if response != 0:
available.append(hostname)
else:
continue
Subprocess.run()将继续循环,尽管在域未注册时会出现!= 0响应。
解决方法
尝试使用<button id="button">Text</button>
代替display='none'
,请参见Running shell command and capturing the output。
exit_code = os.WEXITSTATUS(response)
或
return_value = os.popen("whois " + hostname).read()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。