feat(seautils): added dig command

This commit is contained in:
Seaswimmer 2024-05-28 16:22:22 -04:00
parent 1405dae49e
commit e9c062afa9
Signed by untrusted user: cswimr
GPG key ID: 5D671B5D03D65A7F

View file

@ -5,6 +5,7 @@
# ____) | __/ (_| \__ \\ V V /| | | | | | | | | | | | __/ | # ____) | __/ (_| \__ \\ V V /| | | | | | | | | | | | __/ |
# |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_| # |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_|
import asyncio
import inspect import inspect
import operator import operator
from functools import partial, partialmethod 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)) await ctx.send(embed=embed, reference=ctx.message.to_reference(fail_if_not_exists=False))
else: else:
await ctx.send(content="Object not found!", reference=ctx.message.to_reference(fail_if_not_exists=False)) 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'))