iplookup.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import asyncio
  2. from pyrogram import filters
  3. from pyrogram.types import Message
  4. from wbb import app
  5. from wbb.utils import http
  6. # For /help menu
  7. __MODULE__ = "iplookup"
  8. __HELP__ = """
  9. /iplookup [ip address] to get the details about that ip
  10. """
  11. @app.on_message(filters.command("iplookup"))
  12. async def ip_lookup(_, message: Message):
  13. if len(message.command) < 2:
  14. return await message.reply_text("ip address is missing")
  15. ip_address = message.command[1]
  16. msg = await message.reply_text("checking ip address...")
  17. try:
  18. res = await http.get(f"https://ipinfo.io/{ip_address}/json", timeout=5)
  19. except asyncio.TimeoutError:
  20. return await message.reply_text("request timeout")
  21. except Exception as e:
  22. return await message.reply_text(f"ERROR: `{e}`")
  23. hostname = res.get("hostname", "N/A")
  24. city = res.get("city", "N/A")
  25. region = res.get("region", "N/A")
  26. country = res.get("country", "N/A")
  27. location = res.get("loc", "N/A")
  28. org = res.get("org", "N/A")
  29. await msg.edit(
  30. (
  31. f"**Details of `{ip_address}`**\n\n"
  32. f"HostName: `{hostname}`\n"
  33. f"City: `{city}`\n"
  34. f"Region: `{region}`\n"
  35. f"Country: `{country}`\n"
  36. f"Org: `{org}`\n"
  37. f"Map: https://www.google.fr/maps?q={location}\n"
  38. ),
  39. disable_web_page_preview=True,
  40. )