From e9c062afa951bef99b46c371f77652a92252e7d4 Mon Sep 17 00:00:00 2001 From: Seaswimmer Date: Tue, 28 May 2024 16:22:22 -0400 Subject: [PATCH] feat(seautils): added dig command --- seautils/seautils.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/seautils/seautils.py b/seautils/seautils.py index c575f6b..d2c42b3 100644 --- a/seautils/seautils.py +++ b/seautils/seautils.py @@ -5,6 +5,7 @@ # ____) | __/ (_| \__ \\ V V /| | | | | | | | | | | | __/ | # |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_| +import asyncio import inspect import operator from functools import partial, partialmethod @@ -82,3 +83,22 @@ class SeaUtils(commands.Cog): await ctx.send(embed=embed, reference=ctx.message.to_reference(fail_if_not_exists=False)) else: await ctx.send(content="Object not found!", reference=ctx.message.to_reference(fail_if_not_exists=False)) + + @commands.command(name='dig', aliases=['dnslookup', 'nslookup']) + @commands.is_owner() + async def dig(self, ctx: commands.Context, name: str, type: str | None = 'A', server: str | None = None, port: int = 53) -> None: + """Retrieve DNS information for a domain.""" + command_opts: list[str | int] = ['dig'] + if server: + command_opts.extend(['@', server]) + command_opts.extend([name, type]) + if port != 53: + command_opts.extend(['-p', port]) + command_opts.extend(['+yaml']) + + process = await asyncio.create_subprocess_exec(*command_opts, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) + stdout, stderr = await process.communicate() + if stderr: + await ctx.send(content=cf.box(text=stderr.decode())) + else: + await ctx.send(content=cf.box(text=stdout.decode(), lang='yaml'))