-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
76 lines (63 loc) · 2.23 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
import discord
from discord.ext import commands
import requests
DISCORD_BOT_TOKEN = os.getenv('DISCORD_BOT_TOKEN')
APILAYER_KEY = os.getenv('APILAYER_KEY')
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'Logged in as {bot.user} (ID: {bot.user.id})')
@bot.command(name='whois',
help='Get domain whois information. Usage: !whois <domain>')
async def whois(ctx, domain: str):
if not domain:
await ctx.send('Please provide a domain. Usage: !whois <domain>')
return
headers = {
'apikey': APILAYER_KEY,
}
url = f'https://api.apilayer.com/whois/query?domain={domain}'
response = requests.get(url, headers=headers)
data = response.json()
if response.status_code == 200:
embed = discord.Embed(title="WHOIS Information",
description=f"Domain: {domain}",
color=0x00FF00)
for key, value in data.get('result').items():
embed.add_field(name=key.capitalize(), value=value, inline=False)
await ctx.send(embed=embed)
else:
await ctx.send(
f"Error: {data['message'] if data and data['message'] else 'Unable to execute request'}"
)
@bot.command(
name='dns',
help='Get domain DNS information. Usage: !dns <domain> <record_type>')
async def dns(ctx, domain: str, record_type: str = 'A'):
if not domain:
await ctx.send(
'Please provide a domain. Usage: !dns <domain> <record_type>')
return
headers = {
'apikey': APILAYER_KEY,
}
url = f'https://api.apilayer.com/dns_lookup/api/{record_type}/{domain}'
response = requests.get(url, headers=headers)
data = response.json()
if response.status_code == 200:
embed = discord.Embed(
title="DNS Information",
description=f"Domain: {domain}\nRecord Type: {record_type.capitalize()}",
color=0x00FF00)
for record in data.get('results'):
for key, value in record.items():
embed.add_field(name=key.capitalize(), value=value, inline=False)
await ctx.send(embed=embed)
else:
await ctx.send(
f"Error: {data['message'] if data and data['message'] else 'Unable to execute request'}"
)
bot.run(DISCORD_BOT_TOKEN)