fix(commands:iplocalise|Network): change regex for domain validation

This commit is contained in:
Romain J 2021-03-02 19:00:08 +01:00
parent 34e32fdf68
commit 78a5ac9939
13 changed files with 157 additions and 134 deletions

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Tuxbot-bot\n" "Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n" "Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-01-26 16:12+0100\n" "POT-Creation-Date: 2021-03-01 14:59+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Tuxbot-bot\n" "Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n" "Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-01-26 16:12+0100\n" "POT-Creation-Date: 2021-03-01 14:59+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -26,12 +26,12 @@ msgstr ""
msgid "List of available locales: " msgid "List of available locales: "
msgstr "" msgstr ""
#: tuxbot/cogs/Custom/custom.py:89 #: tuxbot/cogs/Custom/custom.py:93
#, python-brace-format #, python-brace-format
msgid "The alias `{alias}` is already defined for the command `{command}`" msgid "The alias `{alias}` is already defined for the command `{command}`"
msgstr "" msgstr ""
#: tuxbot/cogs/Custom/custom.py:102 #: tuxbot/cogs/Custom/custom.py:106
#, python-brace-format #, python-brace-format
msgid "The alias `{alias}` for the command `{command}` was successfully created" msgid "The alias `{alias}` for the command `{command}` was successfully created"
msgstr "" msgstr ""

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Tuxbot-bot\n" "Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n" "Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-01-26 16:12+0100\n" "POT-Creation-Date: 2021-03-01 14:59+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,10 +17,14 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n" "Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: tuxbot/cogs/Logs/logs.py:295 #: tuxbot/cogs/Logs/logs.py:274
msgid "```An error occurred, the bot owner has been advertised...```"
msgstr ""
#: tuxbot/cogs/Logs/logs.py:333
msgid "Sockets stats" msgid "Sockets stats"
msgstr "" msgstr ""
#: tuxbot/cogs/Logs/logs.py:297 #: tuxbot/cogs/Logs/logs.py:335
msgid "{} socket events observed ({:.2f}/minute):" msgid "{} socket events observed ({:.2f}/minute):"
msgstr "" msgstr ""

View file

@ -126,7 +126,10 @@ class Logs(commands.Cog, name="Logs"):
emoji = types.get(record.levelname, ":heavy_multiplication_x:") emoji = types.get(record.levelname, ":heavy_multiplication_x:")
dt = datetime.datetime.utcfromtimestamp(record.created) dt = datetime.datetime.utcfromtimestamp(record.created)
msg = f"{emoji} `[{dt:%Y-%m-%d %H:%M:%S}] {await shorten(self.bot.session, record.msg, 1500)}`" msg = (
f"{emoji} `[{dt:%Y-%m-%d %H:%M:%S}] "
f"{await shorten(self.bot.session, record.msg, 1500)}`"
)
await self.webhook("gateway").send(msg) await self.webhook("gateway").send(msg)
def clear_gateway_data(self): def clear_gateway_data(self):

View file

@ -0,0 +1,3 @@
DOMAIN_PATTERN = r"^(((.*)+)*\.)+[a-z\-]{2,}\.?$"
IPV4_PATTERN = r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
IPV6_PATTERN = r"^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"

View file

@ -13,27 +13,18 @@ def _(x):
return x return x
DOMAIN_PATTERN = r"^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$"
IPV4_PATTERN = r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
IPV6_PATTERN = r"^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"
class IPConverter(commands.Converter): class IPConverter(commands.Converter):
async def convert(self, ctx, argument): # skipcq: PYL-W0613 async def convert(self, ctx, argument): # skipcq: PYL-W0613
argument = argument.replace("http://", "").replace("https://", "") argument = argument.replace("http://", "").replace("https://", "")
argument = argument.rstrip("/") argument = argument.rstrip("/")
check_domain = re.match(DOMAIN_PATTERN, argument) if argument.startswith("`") and argument.endswith("`"):
check_ipv4 = re.match(IPV4_PATTERN, argument) argument = argument.lstrip("`").rstrip("`")
check_ipv6 = re.match(IPV6_PATTERN, argument)
if check_domain or check_ipv4 or check_ipv6: return argument.lower()
return argument
raise InvalidIp(_("Invalid ip or domain"))
class IPCheckerConverter(commands.Converter): class DomainConverter(commands.Converter):
async def convert(self, ctx, argument): # skipcq: PYL-W0613 async def convert(self, ctx, argument): # skipcq: PYL-W0613
if not argument.startswith("http"): if not argument.startswith("http"):
return f"http://{argument}" return f"http://{argument}"
@ -41,42 +32,9 @@ class IPCheckerConverter(commands.Converter):
return argument return argument
class DomainCheckerConverter(commands.Converter):
async def convert(self, ctx, argument): # skipcq: PYL-W0613
argument = argument.replace("http://", "").replace("https://", "")
check_domain = re.match(DOMAIN_PATTERN, argument)
if check_domain:
return argument
raise InvalidDomain(_("Invalid domain"))
class QueryTypeConverter(commands.Converter): class QueryTypeConverter(commands.Converter):
async def convert(self, ctx, argument): # skipcq: PYL-W0613 async def convert(self, ctx, argument): # skipcq: PYL-W0613
argument = argument.lower() return argument.lower()
query_types = [
"a",
"aaaa",
"cname",
"ns",
"ds",
"dnskey",
"soa",
"txt",
"ptr",
"mx",
]
if argument in query_types:
return argument
raise InvalidQueryType(
_(
"Supported queries : A, AAAA, CNAME, NS, DS, DNSKEY, SOA, TXT, PTR, MX"
)
)
class IPVersionConverter(commands.Converter): class IPVersionConverter(commands.Converter):
@ -84,9 +42,4 @@ class IPVersionConverter(commands.Converter):
if not argument: if not argument:
return argument return argument
argument = argument.replace("-", "").replace("ip", "").replace("v", "") return argument.replace("-", "").replace("ip", "").replace("v", "")
if argument not in ["4", "6"]:
raise InvalidIp(_("Invalid ip version"))
return argument

View file

@ -1,21 +1,25 @@
from discord.ext import commands from discord.ext import commands
class RFC18(commands.UserNotFound): class NetworkException(commands.BadArgument):
pass pass
class InvalidIp(commands.BadArgument): class RFC18(NetworkException):
pass pass
class InvalidDomain(commands.BadArgument): class InvalidIp(NetworkException):
pass pass
class InvalidQueryType(commands.BadArgument): class InvalidDomain(NetworkException):
pass pass
class VersionNotFound(commands.BadArgument): class InvalidQueryType(NetworkException):
pass
class VersionNotFound(NetworkException):
pass pass

View file

@ -1,6 +1,8 @@
import re
import socket import socket
from typing import Union, NoReturn from typing import Union, NoReturn
import discord
import ipinfo import ipinfo
import ipwhois import ipwhois
import pydig import pydig
@ -8,15 +10,22 @@ from ipinfo.exceptions import RequestQuotaExceededError
from ipwhois import Net from ipwhois import Net
from ipwhois.asn import IPASN from ipwhois.asn import IPASN
from tuxbot.cogs.Network.functions.consts import DOMAIN_PATTERN, IPV4_PATTERN, \
IPV6_PATTERN
from tuxbot.cogs.Network.functions.exceptions import VersionNotFound, RFC18 from tuxbot.cogs.Network.functions.exceptions import (
VersionNotFound,
RFC18,
InvalidIp,
InvalidQueryType,
)
def _(x): def _(x):
return x return x
async def get_ip(ip: str, inet: str = "") -> str: async def get_ip(ip: str, inet: str = "", tmp: discord.Message = None) -> str:
if inet == "6": if inet == "6":
inet = socket.AF_INET6 inet = socket.AF_INET6
elif inet == "4": elif inet == "4":
@ -27,6 +36,9 @@ async def get_ip(ip: str, inet: str = "") -> str:
try: try:
return socket.getaddrinfo(str(ip), None, inet)[1][4][0] return socket.getaddrinfo(str(ip), None, inet)[1][4][0]
except socket.gaierror as e: except socket.gaierror as e:
if tmp:
await tmp.delete()
raise VersionNotFound( raise VersionNotFound(
_( _(
"Impossible to collect information on this in the given " "Impossible to collect information on this in the given "
@ -35,14 +47,14 @@ async def get_ip(ip: str, inet: str = "") -> str:
) from e ) from e
def get_hostname(ip: str) -> str: async def get_hostname(ip: str) -> str:
try: try:
return socket.gethostbyaddr(ip)[0] return socket.gethostbyaddr(ip)[0]
except socket.herror: except socket.herror:
return "N/A" return "N/A"
def get_ipwhois_result(ip_address: str) -> Union[NoReturn, dict]: async def get_ipwhois_result(ip_address: str, tmp: discord.Message = None) -> Union[NoReturn, dict]:
try: try:
net = Net(ip_address) net = Net(ip_address)
obj = IPASN(net) obj = IPASN(net)
@ -50,6 +62,9 @@ def get_ipwhois_result(ip_address: str) -> Union[NoReturn, dict]:
except ipwhois.exceptions.ASNRegistryError: except ipwhois.exceptions.ASNRegistryError:
return {} return {}
except ipwhois.exceptions.IPDefinedError as e: except ipwhois.exceptions.IPDefinedError as e:
if tmp:
await tmp.delete()
raise RFC18( raise RFC18(
_( _(
"IP address {ip_address} is already defined as Private-Use" "IP address {ip_address} is already defined as Private-Use"
@ -101,7 +116,7 @@ def merge_ipinfo_ipwhois(ipinfo_result: dict, ipwhois_result: dict) -> dict:
return output return output
def get_pydig_result( async def get_pydig_result(
domain: str, query_type: str, dnssec: Union[str, bool] domain: str, query_type: str, dnssec: Union[str, bool]
) -> list: ) -> list:
additional_args = [] if dnssec is False else ["+dnssec"] additional_args = [] if dnssec is False else ["+dnssec"]
@ -115,3 +130,45 @@ def get_pydig_result(
) )
return resolver.query(domain, query_type) return resolver.query(domain, query_type)
def check_ip_or_raise(ip: str) -> Union[bool, NoReturn]:
check_domain = re.match(DOMAIN_PATTERN, ip)
check_ipv4 = re.match(IPV4_PATTERN, ip)
check_ipv6 = re.match(IPV6_PATTERN, ip)
if check_domain or check_ipv4 or check_ipv6:
return True
raise InvalidIp(_("Invalid ip or domain"))
def check_ip_version_or_raise(version: str) -> Union[bool, NoReturn]:
if version in ["4", "6", ""]:
return True
raise InvalidIp(_("Invalid ip version"))
def check_query_type_or_raise(query_type: str) -> Union[bool, NoReturn]:
query_types = [
"a",
"aaaa",
"cname",
"ns",
"ds",
"dnskey",
"soa",
"txt",
"ptr",
"mx",
]
if query_type in query_types:
return True
raise InvalidQueryType(
_(
"Supported queries : A, AAAA, CNAME, NS, DS, DNSKEY, SOA, TXT, PTR, MX"
)
)

View file

@ -18,62 +18,61 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: tuxbot/cogs/Network/functions/converters.py:32 #: tuxbot/cogs/Network/functions/utils.py:39
#: tuxbot/cogs/Network/functions/converters.py:52
msgid "Invalid ip or domain" msgid "Invalid ip or domain"
msgstr "Nom de domaine ou adresse IP invalide" msgstr "Nom de domaine ou adresse IP invalide"
#: tuxbot/cogs/Network/functions/converters.py:64 #: tuxbot/cogs/Network/functions/utils.py:62
#, python-brace-format
msgid "Invalid domain" msgid "Invalid domain"
msgstr "Domaine invalide" msgstr "Domaine invalide"
#: tuxbot/cogs/Network/functions/converters.py:88 #: tuxbot/cogs/Network/functions/utils.py:135
msgid "Supported queries : A, AAAA, CNAME, NS, DS, DNSKEY, SOA, TXT, PTR, MX" msgid "Supported queries : A, AAAA, CNAME, NS, DS, DNSKEY, SOA, TXT, PTR, MX"
msgstr "Requêtes supportées : A, AAAA, CNAME, NS, DS, DNSKEY, SOA, TXT, PTR, MX" msgstr "Requêtes supportées : A, AAAA, CNAME, NS, DS, DNSKEY, SOA, TXT, PTR, MX"
#: tuxbot/cogs/Network/functions/converters.py:101 #: tuxbot/cogs/Network/functions/utils.py:142
msgid "Invalid ip version" msgid "Invalid ip version"
msgstr "Version d'adresse IP invalide" msgstr "Version d'adresse IP invalide"
#: tuxbot/cogs/Network/functions/utils.py:32 #: tuxbot/cogs/Network/functions/utils.py:164
msgid "Impossible to collect information on this in the given version" msgid "Impossible to collect information on this in the given version"
msgstr "Impossible de collecter des informations pour cette IP avec la version donnée" msgstr "Impossible de collecter des informations pour cette IP avec la version donnée"
#: tuxbot/cogs/Network/functions/utils.py:55 #: tuxbot/cogs/Network/functions/utils.py:164
#, python-brace-format
msgid "IP address {ip_address} is already defined as Private-Use Networks via RFC 1918." msgid "IP address {ip_address} is already defined as Private-Use Networks via RFC 1918."
msgstr "L'adresse ip {ip_address} est est reservée à un usage local selon la RFC 1918" msgstr "L'adresse ip {ip_address} est est reservée à un usage local selon la RFC 1918"
#: tuxbot/cogs/Network/network.py:89 #: tuxbot/cogs/Network/network.py:94
msgid "*Retrieving information...*" msgid "*Retrieving information...*"
msgstr "*Récupération des informations...*" msgstr "*Récupération des informations...*"
#: tuxbot/cogs/Network/network.py:107 #: tuxbot/cogs/Network/network.py:112
#, python-brace-format #, python-brace-format
msgid "Information for ``{ip} ({ip_address})``" msgid "Information for ``{ip} ({ip_address})``"
msgstr "Informations pour ``{ip} ({ip_address})``" msgstr "Informations pour ``{ip} ({ip_address})``"
#: tuxbot/cogs/Network/network.py:113 #: tuxbot/cogs/Network/network.py:118
msgid "Belongs to:" msgid "Belongs to:"
msgstr "Appartient à :" msgstr "Appartient à :"
#: tuxbot/cogs/Network/network.py:123 #: tuxbot/cogs/Network/network.py:128
msgid "Region:" msgid "Region:"
msgstr "Région :" msgstr "Région :"
#: tuxbot/cogs/Network/network.py:131 #: tuxbot/cogs/Network/network.py:136
#, python-brace-format #, python-brace-format
msgid "Hostname: {hostname}" msgid "Hostname: {hostname}"
msgstr "Nom d'hôte : {hostname}" msgstr "Nom d'hôte : {hostname}"
#: tuxbot/cogs/Network/network.py:161 #: tuxbot/cogs/Network/network.py:180
msgid "[show all]({})" msgid "[show all]({})"
msgstr "[tout afficher]({})" msgstr "[tout afficher]({})"
#: tuxbot/cogs/Network/network.py:171 #: tuxbot/cogs/Network/network.py:190
msgid "Cannot connect to host {}" msgid "Cannot connect to host {}"
msgstr "Impossible de se connecter à l'hôte {}" msgstr "Impossible de se connecter à l'hôte {}"
#: tuxbot/cogs/Network/network.py:195 #: tuxbot/cogs/Network/network.py:218
msgid "No result..." msgid "No result..."
msgstr "Aucun résultat..." msgstr "Aucun résultat..."

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Tuxbot-bot\n" "Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n" "Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-01-26 16:12+0100\n" "POT-Creation-Date: 2021-03-01 14:59+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,62 +17,57 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n" "Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: tuxbot/cogs/Network/functions/converters.py:32 #: tuxbot/cogs/Network/functions/utils.py:39
#: tuxbot/cogs/Network/functions/converters.py:52
msgid "Invalid ip or domain"
msgstr ""
#: tuxbot/cogs/Network/functions/converters.py:64
msgid "Invalid domain"
msgstr ""
#: tuxbot/cogs/Network/functions/converters.py:88
msgid "Supported queries : A, AAAA, CNAME, NS, DS, DNSKEY, SOA, TXT, PTR, MX"
msgstr ""
#: tuxbot/cogs/Network/functions/converters.py:101
msgid "Invalid ip version"
msgstr ""
#: tuxbot/cogs/Network/functions/utils.py:32
msgid "Impossible to collect information on this in the given version" msgid "Impossible to collect information on this in the given version"
msgstr "" msgstr ""
#: tuxbot/cogs/Network/functions/utils.py:55 #: tuxbot/cogs/Network/functions/utils.py:62
#, python-brace-format #, python-brace-format
msgid "IP address {ip_address} is already defined as Private-Use Networks via RFC 1918." msgid "IP address {ip_address} is already defined as Private-Use Networks via RFC 1918."
msgstr "" msgstr ""
#: tuxbot/cogs/Network/network.py:89 #: tuxbot/cogs/Network/functions/utils.py:135
msgid "Invalid ip or domain"
msgstr ""
#: tuxbot/cogs/Network/functions/utils.py:142
msgid "Invalid ip version"
msgstr ""
#: tuxbot/cogs/Network/functions/utils.py:164
msgid "Supported queries : A, AAAA, CNAME, NS, DS, DNSKEY, SOA, TXT, PTR, MX"
msgstr ""
#: tuxbot/cogs/Network/network.py:94
msgid "*Retrieving information...*" msgid "*Retrieving information...*"
msgstr "" msgstr ""
#: tuxbot/cogs/Network/network.py:107 #: tuxbot/cogs/Network/network.py:112
#, python-brace-format #, python-brace-format
msgid "Information for ``{ip} ({ip_address})``" msgid "Information for ``{ip} ({ip_address})``"
msgstr "" msgstr ""
#: tuxbot/cogs/Network/network.py:113 #: tuxbot/cogs/Network/network.py:118
msgid "Belongs to:" msgid "Belongs to:"
msgstr "" msgstr ""
#: tuxbot/cogs/Network/network.py:123 #: tuxbot/cogs/Network/network.py:128
msgid "Region:" msgid "Region:"
msgstr "" msgstr ""
#: tuxbot/cogs/Network/network.py:131 #: tuxbot/cogs/Network/network.py:136
#, python-brace-format #, python-brace-format
msgid "Hostname: {hostname}" msgid "Hostname: {hostname}"
msgstr "" msgstr ""
#: tuxbot/cogs/Network/network.py:161 #: tuxbot/cogs/Network/network.py:180
msgid "[show all]({})" msgid "[show all]({})"
msgstr "" msgstr ""
#: tuxbot/cogs/Network/network.py:171 #: tuxbot/cogs/Network/network.py:190
msgid "Cannot connect to host {}" msgid "Cannot connect to host {}"
msgstr "" msgstr ""
#: tuxbot/cogs/Network/network.py:195 #: tuxbot/cogs/Network/network.py:218
msgid "No result..." msgid "No result..."
msgstr "" msgstr ""

View file

@ -13,8 +13,7 @@ from structured_config import ConfigFile
from tuxbot.cogs.Network.functions.converters import ( from tuxbot.cogs.Network.functions.converters import (
IPConverter, IPConverter,
IPVersionConverter, IPVersionConverter,
IPCheckerConverter, DomainConverter,
DomainCheckerConverter,
QueryTypeConverter, QueryTypeConverter,
) )
from tuxbot.cogs.Network.functions.exceptions import ( from tuxbot.cogs.Network.functions.exceptions import (
@ -42,6 +41,9 @@ from .functions.utils import (
get_ipwhois_result, get_ipwhois_result,
merge_ipinfo_ipwhois, merge_ipinfo_ipwhois,
get_pydig_result, get_pydig_result,
check_ip_or_raise,
check_query_type_or_raise,
check_ip_version_or_raise,
) )
log = logging.getLogger("tuxbot.cogs.Network") log = logging.getLogger("tuxbot.cogs.Network")
@ -49,8 +51,6 @@ _ = Translator("Network", __file__)
class Network(commands.Cog, name="Network"): class Network(commands.Cog, name="Network"):
_tmp: discord.Message
def __init__(self, bot: Tux): def __init__(self, bot: Tux):
self.bot = bot self.bot = bot
self.__config: NetworkConfig = ConfigFile( self.__config: NetworkConfig = ConfigFile(
@ -59,6 +59,9 @@ class Network(commands.Cog, name="Network"):
).config ).config
async def cog_command_error(self, ctx, error): async def cog_command_error(self, ctx, error):
self.bot.console.log("Pass here")
self.bot.console.log(error)
self.bot.console.log(type(error))
if isinstance( if isinstance(
error, error,
( (
@ -70,8 +73,7 @@ class Network(commands.Cog, name="Network"):
VersionNotFound, VersionNotFound,
), ),
): ):
if self._tmp: self.bot.console.log("Pass there")
await self._tmp.delete()
await ctx.send(_(str(error), ctx, self.bot.config)) await ctx.send(_(str(error), ctx, self.bot.config))
@ -85,20 +87,21 @@ class Network(commands.Cog, name="Network"):
ip: IPConverter, ip: IPConverter,
version: IPVersionConverter = "", version: IPVersionConverter = "",
): ):
self._tmp = await ctx.send( check_ip_or_raise(str(ip))
check_ip_version_or_raise(str(version))
tmp = await ctx.send(
_("*Retrieving information...*", ctx, self.bot.config), _("*Retrieving information...*", ctx, self.bot.config),
deletable=False, deletable=False,
) )
ip_address = await get_ip(str(ip), str(version)) ip_address = await get_ip(str(ip), str(version), tmp)
ip_hostname = get_hostname(ip_address) ip_hostname = await get_hostname(ip_address)
ipinfo_result = await get_ipinfo_result( ipinfo_result = await get_ipinfo_result(
self.__config.ipinfoKey, ip_address self.__config.ipinfoKey, ip_address
) )
ipwhois_result = await self.bot.loop.run_in_executor( ipwhois_result = await get_ipwhois_result(ip_address, tmp)
None, functools.partial(get_ipwhois_result, ip_address)
)
merged_results = merge_ipinfo_ipwhois(ipinfo_result, ipwhois_result) merged_results = merge_ipinfo_ipwhois(ipinfo_result, ipwhois_result)
@ -133,12 +136,12 @@ class Network(commands.Cog, name="Network"):
), ),
) )
await self._tmp.delete() await tmp.delete()
await ctx.send(embed=e) await ctx.send(embed=e)
@command_extra(name="getheaders", aliases=["headers"], deletable=True) @command_extra(name="getheaders", aliases=["headers"], deletable=True)
async def _getheaders( async def _getheaders(
self, ctx: ContextPlus, ip: IPCheckerConverter, *, user_agent: str = "" self, ctx: ContextPlus, ip: DomainConverter, *, user_agent: str = ""
): ):
try: try:
headers = {"User-Agent": user_agent} headers = {"User-Agent": user_agent}
@ -189,10 +192,12 @@ class Network(commands.Cog, name="Network"):
async def _dig( async def _dig(
self, self,
ctx: ContextPlus, ctx: ContextPlus,
domain: DomainCheckerConverter, domain: IPConverter,
query_type: QueryTypeConverter, query_type: QueryTypeConverter,
dnssec: Union[str, bool] = False, dnssec: Union[str, bool] = False,
): ):
check_query_type_or_raise(str(query_type))
pydig_result = await self.bot.loop.run_in_executor( pydig_result = await self.bot.loop.run_in_executor(
None, None,
functools.partial(get_pydig_result, domain, query_type, dnssec), functools.partial(get_pydig_result, domain, query_type, dnssec),
@ -200,9 +205,9 @@ class Network(commands.Cog, name="Network"):
e = discord.Embed(title=f"DIG {domain} {query_type}", color=0x5858D7) e = discord.Embed(title=f"DIG {domain} {query_type}", color=0x5858D7)
for value in pydig_result: for i, value in enumerate(pydig_result):
e.add_field( e.add_field(
name=f"DIG {domain} IN {query_type}", value=f"```{value}```" name=f"#{i}", value=f"```{value}```"
) )
if not pydig_result: if not pydig_result:

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Tuxbot-bot\n" "Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n" "Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-01-26 16:12+0100\n" "POT-Creation-Date: 2021-03-01 14:59+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Tuxbot-bot\n" "Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n" "Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-01-26 16:12+0100\n" "POT-Creation-Date: 2021-03-01 14:59+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"