86 lines
2.4 KiB
Python
86 lines
2.4 KiB
Python
import whois
|
|
import http.client
|
|
import json
|
|
import hashlib
|
|
import base64
|
|
import hmac
|
|
import datetime
|
|
|
|
|
|
def gen_sign(timestamp, secret):
|
|
# 拼接timestamp和secret
|
|
string_to_sign = "{}\n{}".format(timestamp, secret)
|
|
hmac_code = hmac.new(
|
|
string_to_sign.encode("utf-8"), digestmod=hashlib.sha256
|
|
).digest()
|
|
|
|
# 对结果进行base64处理
|
|
sign = base64.b64encode(hmac_code).decode("utf-8")
|
|
return sign
|
|
|
|
|
|
def check_domain_availability(domain_name):
|
|
"""检查域名是否注册"""
|
|
message = ""
|
|
try:
|
|
w = whois.whois(domain_name)
|
|
|
|
expiration_date = w.expiration_date
|
|
if type(expiration_date) == list:
|
|
expiration_date = expiration_date[0]
|
|
expiration_date = expiration_date.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
if w.domain_name:
|
|
# print(f"域名: {domain_name} 已被注册, 到期时间: {expiration_date}")
|
|
message = f"域名: {domain_name} 已被注册, 到期时间: {expiration_date}"
|
|
else:
|
|
# print(f"域名: {domain_name} 可以注册")
|
|
message = f"域名: {domain_name} 可以注册 **"
|
|
|
|
except Exception as e:
|
|
# print(f"域名: {domain_name} 可以注册")
|
|
message = f"域名: {domain_name} 可以注册, {e} **"
|
|
return message
|
|
|
|
|
|
def feishu_notify(text):
|
|
|
|
webhook_url = "/open-apis/bot/v2/hook/1035a9dc-ea2d-49b6-bd6e-67faaa1844db"
|
|
Keys = "RgfybKsP8eU5l9u24BLPHb"
|
|
|
|
conn = http.client.HTTPSConnection("open.feishu.cn")
|
|
payload = json.dumps({"msg_type": "text", "content": {"text": text}})
|
|
headers = {"Content-Type": "application/json"}
|
|
conn.request("POST", webhook_url, payload, headers)
|
|
res = conn.getresponse()
|
|
data = res.read()
|
|
# print(data.decode("utf-8"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
domain_list = [
|
|
"woni.com",
|
|
"woni.cn",
|
|
"woni.cc",
|
|
"woni.me",
|
|
"guanzhu.com",
|
|
"guanzhu.cn",
|
|
"guanzhu.cc",
|
|
"guanzhu.me",
|
|
]
|
|
|
|
messages = []
|
|
# 获取今天的日期
|
|
today = datetime.date.today()
|
|
messages.append(f"域名注册 {today.strftime('%Y-%m-%d')} 检查结果:")
|
|
for domain in domain_list:
|
|
print(f"检查域名: {domain}")
|
|
message = check_domain_availability(domain)
|
|
print(message)
|
|
messages.append(message)
|
|
|
|
print("开始发送飞书消息")
|
|
feishu_notify("\n".join(messages))
|
|
print("发送飞书消息成功")
|