import requests
import pandas as pd
from openpyxl import Workbook
# 读取域名文件
with open("domains.txt", "r") as f:
domains = f.readlines()
# 去除注释和空行
domains = [line.strip() for line in domains if not line.startswith("#") and line.strip()]
# 创建工作簿
wb = Workbook()
ws = wb.active
# 写入表头
ws.append(["域名", "IP地址", "最近更新时间", "子域名", "子域名最近更新时间"])
# 循环查询域名信息
for domain in domains:
try:
# 发送请求
response = requests.get(f"https://sc.360.net/api/domain/query?domain={domain}")
response.raise_for_status() # 检查请求是否成功
data = response.json()
# 获取IP地址和更新时间
ip_address = data.get("ip", [])
latest_update = data.get("update_time", "")
# 获取子域名和更新时间
subdomains = data.get("subdomain", [])
subdomain_updates = data.get("subdomain_update_time", [])
# 循环写入数据
for i in range(len(ip_address)):
ws.append([
domain,
ip_address[i],
latest_update,
subdomains[i],
subdomain_updates[i]
])
except Exception as e:
print(f"Error querying domain {domain}: {e}")
# 保存xlsx文件
wb.save("domain_info.xlsx")