bot: Add dig command
All checks were successful
Build Docker / Build Docker (push) Successful in 28s

This commit is contained in:
Nathan Woodburn 2023-08-11 17:24:11 +10:00
parent b8b372c1d2
commit c5ef0b6c8a
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 34 additions and 1 deletions

32
bot.py
View File

@ -3,6 +3,8 @@ from dotenv import load_dotenv
import discord
from discord import app_commands
import requests
import socket
import dns.resolver
load_dotenv()
@ -57,6 +59,36 @@ async def botstatus(ctx, message: str, statusmethod: str = None):
updateStatus()
await ctx.response.send_message("Status updated",ephemeral=True)
@tree.command(name="dig", description="Dig a dns record")
async def dig(ctx, domain: str, record_type: str = "A"):
record_type = record_type.upper()
# Format dig @100.74.29.146 -p 5350 <domain> <type>
resolver = dns.resolver.Resolver()
resolver.nameservers = ["100.74.29.146"]
resolver.port = 5350
try:
# Query the DNS record
response = resolver.query(domain, record_type)
print(response)
records = ""
for record in response:
print(record)
records = records + "\n" + str(record)
# Send the result to the Discord channel
await ctx.response.send_message(f"DNS records for {domain} ({record_type}):{records}")
except dns.resolver.NXDOMAIN:
await ctx.response.send_message(f"Domain {domain} not found.")
except dns.exception.DNSException as e:
await ctx.response.send_message(f"An error occurred: {e}")
async def log(message):
channel=client.get_channel(logChannel)

View File

@ -1,3 +1,4 @@
discord.py
python-dotenv
requests
dnspython