iShotaBot/defs/ip.py

42 lines
1.3 KiB
Python
Raw Permalink Normal View History

2022-07-25 10:04:36 +00:00
import contextlib
def ip_info(url, ipinfo_json):
ipinfo_list = [f"查询目标: `{url}`"]
2023-01-12 13:19:54 +00:00
if ipinfo_json["query"] != url:
ipinfo_list.extend(["解析地址: `" + ipinfo_json["query"] + "`"])
ipinfo_list.extend(
[
"地区: `"
+ ipinfo_json["country"]
+ " - "
+ ipinfo_json["regionName"]
+ " - "
+ ipinfo_json["city"]
+ "`"
]
)
ipinfo_list.extend(
["经纬度: `" + str(ipinfo_json["lat"]) + "," + str(ipinfo_json["lon"]) + "`"]
)
ipinfo_list.extend(["ISP `" + ipinfo_json["isp"] + "`"])
if ipinfo_json["org"] != "":
ipinfo_list.extend(["组织: `" + ipinfo_json["org"] + "`"])
2022-07-25 10:04:36 +00:00
with contextlib.suppress(Exception):
ipinfo_list.extend(
2023-01-12 13:19:54 +00:00
[
"["
+ ipinfo_json["as"]
+ "](https://bgp.he.net/"
+ ipinfo_json["as"].split()[0]
+ ")"
]
)
if ipinfo_json["mobile"]:
ipinfo_list.extend(["此 IP 可能为**蜂窝移动数据 IP**"])
if ipinfo_json["proxy"]:
ipinfo_list.extend(["此 IP 可能为**代理 IP**"])
if ipinfo_json["hosting"]:
ipinfo_list.extend(["此 IP 可能为**数据中心 IP**"])
return "\n".join(ipinfo_list)