import requests
from bs4 import BeautifulSoup
from nonebot import on, on_command
from nonebot.rule import to_me
from nonebot.matcher import Matcher
from nonebot.adapters import Message
from nonebot.params import Arg, CommandArg, ArgPlainText
from nonebot.adapters.onebot.v11 import Message, MessageSegment
import asyncio
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Cookie': 'PHPSESSID=lj0tsuf8poheud74qbbgp8o4c4',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'none',
'Sec-Fetch-User': '?1',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.53',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="101", "Microsoft Edge";v="101"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"'
}
payload = {}
searchfileform = on_command('searchfileform', aliases={'查询文件头', '文件头'}, priority=5)
@searchfileform.handle()
async def searchfileform_(matcher: Matcher, args: Message = CommandArg()):
houzhuiming = args.extract_plain_text()
if houzhuiming:
try:
url = "https://filesignatures.net/index.php?page=search&search={0}&mode=EXT".format(houzhuiming)
response = requests.request("GET", url, headers=headers, data=payload)
soup = BeautifulSoup(response.text, 'html.parser')
selector = soup.select('#results > a')
text = "[+] 查询成功!"+Message('[CQ:face,id=324]')+"\n[+] 文件后缀为:"+selector[0].get_text()+"\n[+] 文件头为:"+selector[1].get_text()
await matcher.send(text)
except Exception as e:
await matcher.send("[-] 查询失败!"+Message('[CQ:face,id=173]')+"\n[-] "+str(e))
re_searchfileform = on_command('re_searchfileform', aliases={'反查文件头'}, priority=5)
@re_searchfileform.handle()
async def re_searchfileform_(matcher: Matcher, args: Message = CommandArg()):
qianzhui = args.extract_plain_text()
url = "https://filesignatures.net/index.php?search={0}&mode=SIG".format(qianzhui.strip(' '))
if qianzhui:
try :
response = requests.request("GET", url, headers=headers, data=payload)
soup = BeautifulSoup(response.text, 'html.parser')
selector = soup.select('#results > a')
text = ''
for i in range(0,len(selector),2):
text = text+selector[i].get_text()+","
if text:
text = text[:-1]
text = "[+] 查询成功!"+Message('[CQ:face,id=324]')+"\n[+] 可能的文件类型为:\n"+text
await matcher.send(text)
else:
await matcher.send("[-] 查询失败!"+Message('[CQ:face,id=173]'))
except Exception as e:
await matcher.send("[-] 查询失败!"+Message('[CQ:face,id=173]')+"\n[-] "+str(e))

- 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
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65