2022-07-25 10:04:36 +00:00
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
|
|
|
from pyrogram import Client, filters
|
|
|
|
from pyrogram.types import Message
|
|
|
|
|
|
|
|
from defs.ip import ip_info
|
2022-07-25 10:17:37 +00:00
|
|
|
from init import user_me, request
|
2022-07-25 10:04:36 +00:00
|
|
|
|
|
|
|
|
2023-01-12 13:19:54 +00:00
|
|
|
@Client.on_message(filters.incoming & filters.command(["ip", f"ip@{user_me.username}"]))
|
2022-07-25 10:04:36 +00:00
|
|
|
async def ip_command(_: Client, message: Message):
|
2023-01-12 13:19:54 +00:00
|
|
|
msg = await message.reply("正在查询中...")
|
|
|
|
rep_text = ""
|
2022-07-25 10:04:36 +00:00
|
|
|
reply = message.reply_to_message
|
|
|
|
if reply:
|
|
|
|
if reply.entities:
|
|
|
|
for num in range(0, len(reply.entities)):
|
|
|
|
url = reply.text[
|
2023-01-12 13:19:54 +00:00
|
|
|
reply.entities[num].offset : reply.entities[num].offset
|
|
|
|
+ reply.entities[num].length
|
|
|
|
]
|
2022-07-25 10:04:36 +00:00
|
|
|
url = urlparse(url)
|
|
|
|
if url.hostname or url.path:
|
|
|
|
if url.hostname:
|
|
|
|
url = url.hostname
|
|
|
|
else:
|
|
|
|
url = url.path
|
2023-01-12 13:19:54 +00:00
|
|
|
ipinfo_json = (
|
|
|
|
await request.get(
|
|
|
|
"http://ip-api.com/json/"
|
|
|
|
+ url
|
|
|
|
+ "?fields=status,message,country,regionName,city,"
|
|
|
|
"lat,lon,isp,"
|
|
|
|
"org,as,mobile,proxy,hosting,query"
|
|
|
|
)
|
|
|
|
).json()
|
|
|
|
if ipinfo_json["status"] == "fail":
|
2022-07-25 10:04:36 +00:00
|
|
|
pass
|
2023-01-12 13:19:54 +00:00
|
|
|
elif ipinfo_json["status"] == "success":
|
2022-07-25 10:04:36 +00:00
|
|
|
rep_text = ip_info(url, ipinfo_json)
|
2023-01-12 13:19:54 +00:00
|
|
|
text = ""
|
2022-07-25 10:04:36 +00:00
|
|
|
if message.entities:
|
|
|
|
for num in range(0, len(message.entities)):
|
|
|
|
url = message.text[
|
2023-01-12 13:19:54 +00:00
|
|
|
message.entities[num].offset : message.entities[num].offset
|
|
|
|
+ message.entities[num].length
|
|
|
|
]
|
2022-07-25 10:04:36 +00:00
|
|
|
url = urlparse(url)
|
|
|
|
if url.hostname or url.path:
|
|
|
|
if url.hostname:
|
|
|
|
url = url.hostname
|
|
|
|
else:
|
|
|
|
url = url.path
|
2023-01-12 13:19:54 +00:00
|
|
|
ipinfo_json = (
|
|
|
|
await request.get(
|
|
|
|
"http://ip-api.com/json/"
|
|
|
|
+ url
|
|
|
|
+ "?fields=status,message,country,regionName,city,lat,"
|
|
|
|
"lon,isp,"
|
|
|
|
"org,as,mobile,proxy,hosting,query"
|
|
|
|
)
|
|
|
|
).json()
|
|
|
|
if ipinfo_json["status"] == "fail":
|
2022-07-25 10:04:36 +00:00
|
|
|
pass
|
2023-01-12 13:19:54 +00:00
|
|
|
elif ipinfo_json["status"] == "success":
|
2022-07-25 10:04:36 +00:00
|
|
|
text = ip_info(url, ipinfo_json)
|
2023-01-12 13:19:54 +00:00
|
|
|
if text == "":
|
2022-07-25 10:04:36 +00:00
|
|
|
url = message.text[4:]
|
2023-01-12 13:19:54 +00:00
|
|
|
if not url == "":
|
|
|
|
ipinfo_json = (
|
|
|
|
await request.get(
|
|
|
|
"http://ip-api.com/json/"
|
|
|
|
+ url
|
|
|
|
+ "?fields=status,message,country,regionName,city,lat,"
|
|
|
|
"lon,isp,"
|
|
|
|
"org,as,mobile,proxy,hosting,query"
|
|
|
|
)
|
|
|
|
).json()
|
|
|
|
if ipinfo_json["status"] == "fail":
|
2022-07-25 10:04:36 +00:00
|
|
|
pass
|
2023-01-12 13:19:54 +00:00
|
|
|
elif ipinfo_json["status"] == "success":
|
2022-07-25 10:04:36 +00:00
|
|
|
text = ip_info(url, ipinfo_json)
|
2023-01-12 13:19:54 +00:00
|
|
|
if rep_text == "" and text == "":
|
|
|
|
await msg.edit("没有找到要查询的 ip/域名 ...")
|
|
|
|
elif not rep_text == "" and not text == "":
|
|
|
|
await msg.edit(f"{rep_text}\n================\n{text}")
|
2022-07-25 10:04:36 +00:00
|
|
|
else:
|
2023-01-12 13:19:54 +00:00
|
|
|
await msg.edit(f"{rep_text}{text}")
|