forked from dompling/PagerMaid_Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
whois.py
33 lines (31 loc) · 1.47 KB
/
whois.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import json
from json import JSONDecodeError
from requests import get
from pagermaid.listener import listener
from pagermaid.utils import obtain_message, alias_command
@listener(outgoing=True, command=alias_command("whois"),
description="查看域名是否已被注册、注册日期、过期日期、域名状态、DNS解析服务器等。")
async def whois(context):
await context.edit("获取中 . . .")
try:
message = await obtain_message(context)
except ValueError:
await context.edit("出错了呜呜呜 ~ 无效的参数。")
return
req = get("https://tenapi.cn/whois/?url=" + message)
if req.status_code == 200:
try:
data = json.loads(req.text)['data']
except KeyError:
await context.edit("出错了呜呜呜 ~ 可能是域名不正确。")
return
except JSONDecodeError:
await context.edit("出错了呜呜呜 ~ 可能是域名不正确。")
return
res = '域名: `' + data['url'] + '`\n注册商: `' + str(data['registrar']) + '`\n联系人: `' + str(
data['registrant']) + '`\n联系邮箱: `' + str(data['mail']) + '`\n注册时间: `' + str(
data['registration']) + '`\n过期时间: `' + str(data['expiration']) + '`\nDNS: ' + str(data['dns']).replace(
'<br/>', '\n')
await context.edit(res)
else:
await context.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")