使用域名列表做一个whois

And*_*y K 3 whois pywhois web

我有一个域名文件,例如相当于2500.

我想对这些域名做一个whois.

问题是我从来没有这样做过,也不知道从哪里开始.如果你有任何想法,我会全力以赴.

TIA.

Alu*_*Alu 7

您也可以使用Linux commandtool whois.以下代码打开子进程并搜索域.

但是你必须在短时间内注意许多要求.一段时间后服务器最终会阻止你.;)

import subprocess

def find_whois(domain):
    # Linux 'whois' command wrapper
    # 
    # Executes a whois lookup with the linux command whois.
    # Returncodes from: https://github.com/rfc1036/whois/blob/master/whois.c

    domain = domain.lower().strip()
    d = domain.split('.')
    if d[0] == 'www': d = d[1:]

    # Run command with timeout
    proc = subprocess.Popen(['whois', domain], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    ans,err = proc.communicate(input)

    if err == 1: raise WhoisError('No Whois Server for this TLD or wrong query syntax') 
    elif err == 2: raise WhoisError('Whois has timed out after ' + str(whois_timeout) + ' seconds. (try again later or try higher timeout)')
    ans = ans.decode('UTF-8')
    return ans


with open('domains.txt') as input:
    with open('out.txt','a') as output:
        for line in input:
            output.write(find_whois(line))
Run Code Online (Sandbox Code Playgroud)

with open as语句处理文件流.输出文件中的"a"表示文件以append-mode打开.