forked from friendly-telegram/modules-repo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiplookup.py
executable file
·44 lines (30 loc) · 1.13 KB
/
iplookup.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
34
35
36
37
38
39
40
41
42
43
44
import logging
from re import sub
from requests import get
from .. import loader, utils
logger = logging.getLogger(__name__)
@loader.tds
class IPLookupMod(loader.Module):
"""IP lookup using ip-api.com"""
strings = {"name": "IP Lookup"}
def __init__(self):
self.name = self.strings["name"]
async def ipcmd(self, message):
"""Use as .ip <ip> (optional)"""
ip = utils.get_args_raw(message)
lookup = get(f"http://ip-api.com/json/{ip}").json()
fixed_lookup = {}
for key, value in lookup.items():
special = {"lat": "Latitude", "lon": "Longitude", "isp": "ISP", "as": "AS", "asname": "AS name"}
if key in special:
fixed_lookup[special[key]] = str(value)
continue
key = sub(r"([a-z])([A-Z])", r"\g<1> \g<2>", key)
key = key.capitalize()
if not value:
value = "None"
fixed_lookup[key] = str(value)
text = ""
for key, value in fixed_lookup.items():
text = text + f"<b>{key}:</b> <code>{value}</code>\n"
await utils.answer(message, text)