77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
@File : getDomain.py
|
|
@Author : lichao
|
|
@Date : 2024/11/25 16:09
|
|
@Software : PyCharm
|
|
"""
|
|
|
|
import whois
|
|
import concurrent.futures
|
|
from get_Combine import generate_combinations
|
|
|
|
|
|
def check_domain_registration(domain):
|
|
try:
|
|
# 使用 whois 查询域名信息
|
|
domain_info = whois.whois(domain)
|
|
|
|
# 如果是 .de 域名,直接检查 Status 字段
|
|
if domain.endswith(".de"):
|
|
status_line = domain_info.get('status', '').lower()
|
|
if 'free' in status_line:
|
|
return (domain, False) # 域名未注册
|
|
else:
|
|
return (domain, True) # 域名已注册
|
|
|
|
# 判断返回的数据是否为空,通常空数据表示域名未注册
|
|
if domain_info is None or not domain_info.domain_name:
|
|
return (domain, False)
|
|
else:
|
|
return (domain, True)
|
|
|
|
except Exception as e:
|
|
# 捕获任何异常并处理未注册的情况
|
|
return (domain, False)
|
|
|
|
|
|
def check_domains_in_parallel(domains):
|
|
results = []
|
|
|
|
# 使用 ThreadPoolExecutor 进行并行查询
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
|
|
# 提交所有查询任务
|
|
future_to_domain = {executor.submit(check_domain_registration, domain): domain for domain in domains}
|
|
|
|
# 获取查询结果
|
|
for future in concurrent.futures.as_completed(future_to_domain):
|
|
domain = future_to_domain[future]
|
|
try:
|
|
result = future.result()
|
|
results.append(result)
|
|
except Exception as exc:
|
|
print(f"{domain} 产生了一个异常: {exc}")
|
|
|
|
return results
|
|
|
|
# strings = generate_combinations(1,'.de')
|
|
#
|
|
# print(len(strings),strings)
|
|
|
|
# 测试例子
|
|
domains_to_check = [
|
|
".de",
|
|
]
|
|
|
|
# 并行查询
|
|
results = check_domains_in_parallel(domains_to_check)
|
|
|
|
# 打印结果
|
|
for domain, is_registered in results:
|
|
if is_registered:
|
|
print(f"域名 {domain} 已被注册。")
|
|
else:
|
|
print(f"域名 {domain} 未被注册。")
|
|
|