以下是一個使用Visual Studio Code的Python腳本,使用多線程線程池查詢域名可用性,並自動生成4位數英文或數字的.com域名並寫入txt檔案。

import whois
import random
import string
import concurrent.futures

def generate_domain():
    """生成4位數英文或數字的.com域名"""
    letters = string.ascii_lowercase + string.digits
    return ''.join(random.choice(letters) for i in range(4)) + '.com'

def check_availability(domain):
    """檢查域名是否可用"""
    try:
        w = whois.whois(domain)
        return not w.domain_name
    except:
        return False

def main():
    # 創建一個線程池
    with concurrent.futures.ThreadPoolExecutor() as executor:
        # 創建一個txt檔案
        with open('available_domains.txt', 'w') as f:
            # 生成100個域名並檢查可用性
            results = [executor.submit(check_availability, generate_domain()) for i in range(100)]
            # 將可用的域名寫入檔案
            for r in concurrent.futures.as_completed(results):
                if r.result():
                    f.write(r.result() + '\n')

if __name__ == '__main__':
    main()

這個腳本會生成100個域名,並使用多線程線程池檢查它們的可用性。可用的域名會被寫入一個新的txt檔案中。注意,由於域名查詢需要時間,腳本的執行時間可能會比較長

visual stuidio code python whois 運用多線程線程池查詢域名可用性 自動生成4位數英文或者數字的com域名寫入txt檔案

原文地址: https://www.cveoy.top/t/topic/gIE8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录