mirror of
https://github.com/TeamPGM/PagerMaid_Plugins_Pyro.git
synced 2024-11-16 05:45:24 +00:00
gfw 查询是否被墙 (#115)
Co-authored-by: omg-xtao <100690902+omg-xtao@users.noreply.github.com>
This commit is contained in:
parent
a8606b15dc
commit
daff9245d7
67
gfw/main.py
Normal file
67
gfw/main.py
Normal file
@ -0,0 +1,67 @@
|
||||
from pagermaid.listener import listener
|
||||
from pagermaid.enums import Message
|
||||
from pagermaid.services import client as requests
|
||||
|
||||
import socket
|
||||
|
||||
|
||||
def is_ip(ip):
|
||||
try:
|
||||
socket.inet_aton(ip)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def get_ip(domain):
|
||||
try:
|
||||
ip = socket.gethostbyname(domain)
|
||||
except Exception:
|
||||
return None
|
||||
return ip
|
||||
|
||||
|
||||
async def post(host):
|
||||
url = 'https://api.potatonet.idc.wiki/network/simple_health_check/scripts/gfw_check'
|
||||
data = {'host': host}
|
||||
return await requests.post(url, data=data)
|
||||
|
||||
|
||||
@listener(command="gfw",
|
||||
parameters="<text>",
|
||||
description="查询是否被墙")
|
||||
async def gfw(message: Message):
|
||||
text = None
|
||||
if message.arguments:
|
||||
text = message.arguments
|
||||
elif message.reply_to_message:
|
||||
text = message.reply_to_message.text
|
||||
if not text:
|
||||
return await message.edit("请输入或回复一个IP或域名。")
|
||||
try:
|
||||
if not is_ip(text):
|
||||
if get_ip(text) is None:
|
||||
return await message.edit("出错了呜呜呜 ~ 无效的参数。")
|
||||
else:
|
||||
text = get_ip(text)
|
||||
try:
|
||||
message: Message = await message.edit(f"{text} 查询中...")
|
||||
except Exception:
|
||||
return await message.edit("出错了呜呜呜 ~ 无效的参数。")
|
||||
data = await post(text)
|
||||
data = data.json()
|
||||
except Exception as e:
|
||||
return await message.edit(f"出错了呜呜呜 ~ 查询失败。{e}")
|
||||
|
||||
if data['success']:
|
||||
if data['data']['tcp']['cn'] == data['data']['tcp']['!cn'] and data['data']['icmp']['cn'] == \
|
||||
data['data']['icmp']['!cn']:
|
||||
if data['data']['tcp']['cn'] == False and data['data']['icmp']['cn'] == False:
|
||||
reply = f"IP: {text}\n状态: 全球不通,不能判断是否被墙"
|
||||
else:
|
||||
reply = f"IP: {text}\n状态: 未被墙"
|
||||
else:
|
||||
reply = f"IP: {text}\n状态: 被墙"
|
||||
else:
|
||||
reply = f"IP: {text}\n状态: 查询失败"
|
||||
return await message.edit(reply)
|
10
list.json
10
list.json
@ -879,6 +879,16 @@
|
||||
"supported": true,
|
||||
"des-short": "copy_sticker_set 复制整个贴纸包",
|
||||
"des": "copy_sticker_set 复制整个贴纸包"
|
||||
},
|
||||
{
|
||||
"name": "gfw",
|
||||
"version": "1.0",
|
||||
"section": "chat",
|
||||
"maintainer": "M1saka10010",
|
||||
"size": "2.04 kb",
|
||||
"supported": true,
|
||||
"des-short": "gfw 查询ip或域名是否被墙",
|
||||
"des": "gfw 查询ip或域名是否被墙"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user