bot: Add dig command
All checks were successful
Build Docker / Build Docker (push) Successful in 28s
All checks were successful
Build Docker / Build Docker (push) Successful in 28s
This commit is contained in:
parent
b8b372c1d2
commit
c5ef0b6c8a
32
bot.py
32
bot.py
@ -3,6 +3,8 @@ from dotenv import load_dotenv
|
|||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
import requests
|
import requests
|
||||||
|
import socket
|
||||||
|
import dns.resolver
|
||||||
|
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@ -57,6 +59,36 @@ async def botstatus(ctx, message: str, statusmethod: str = None):
|
|||||||
updateStatus()
|
updateStatus()
|
||||||
await ctx.response.send_message("Status updated",ephemeral=True)
|
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):
|
async def log(message):
|
||||||
channel=client.get_channel(logChannel)
|
channel=client.get_channel(logChannel)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
discord.py
|
discord.py
|
||||||
python-dotenv
|
python-dotenv
|
||||||
requests
|
requests
|
||||||
|
dnspython
|
Loading…
Reference in New Issue
Block a user