whois command

This commit is contained in:
kiriharu 2021-01-04 00:45:32 +03:00
parent 28386de8fa
commit 2ad86d1bb6
3 changed files with 38 additions and 0 deletions

View File

@ -9,6 +9,7 @@ python = "^3.8"
aiogram = "^2.11.2" aiogram = "^2.11.2"
core = {path = "../core"} core = {path = "../core"}
httpx = "^0.16.1" httpx = "^0.16.1"
python-whois = "^0.7.3"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]

View File

@ -2,8 +2,10 @@ from aiogram import Dispatcher
from .start import start_cmd from .start import start_cmd
from .web import web_cmd from .web import web_cmd
from .whois import whois_cmd
def setup(dp: Dispatcher): def setup(dp: Dispatcher):
dp.register_message_handler(start_cmd, commands=['start']) dp.register_message_handler(start_cmd, commands=['start'])
dp.register_message_handler(web_cmd, commands=['web', 'http']) dp.register_message_handler(web_cmd, commands=['web', 'http'])
dp.register_message_handler(whois_cmd, commands=['whois'])

View File

@ -0,0 +1,35 @@
from aiogram.types import Message
import whois
whois_help_message = """
Вернёт информацию о домене.
Использование: `/whois <домен>`
"""
no_domain_text = """
Не указан домен или указан неверный/несуществующий домен.
Напишите /whois чтобы посмотреть справку.
"""
def create_whois_message(domain: str) -> str:
domain_info = whois.whois(domain)
if domain_info.get("domain_name") is None:
return no_domain_text
message = f"\n📝Имя: {domain_info.get('domain_name')}" \
f"\n👤Регистратор: {domain_info.get('registrar')}" \
f"\n📅Дата создания: {domain_info.get('creation_date')}" \
f"\n📅Дата окончания: {domain_info.get('expiration_date')}" \
f"\n📌NS: {' '.join(domain_info.get('name_servers'))}"
return message
async def whois_cmd(msg: Message):
args = msg.text.split(" ")
if len(args) == 1:
return await msg.answer(no_domain_text)
if len(args) >= 2:
host = args[1]
await msg.answer(create_whois_message(host))