-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
290 lines (240 loc) · 11.6 KB
/
main.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import discord
from discord.ext import commands
import requests
import json
import logging
import whois
from dotenv import dotenv_values
intents = discord.Intents.default()
intents.messages = True
intents.guilds = True
# Configure logging
logging.basicConfig(filename='logger.txt', level=logging.INFO,
format='%(asctime)s [%(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
# Read config from .env
config = dotenv_values(".env")
# Access token and guild ID
TOKEN = config.get('TOKEN')
GUILD_ID = int(config.get('GUILDID'))
bot = commands.Bot(command_prefix='/', intents=intents)
API_BASE_URL = 'https://api.hackertarget.com/'
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="networks"))
# Sync the slash commands with Discord
await bot.tree.sync()
async def print_error(e: Exception, interaction: discord.Interaction):
error_msg = f'Error: {e}'
logging.error(error_msg)
await interaction.response.send_message(error_msg)
@bot.tree.command(name='check', description="Check any IP")
async def check_ip_info(interaction: discord.Interaction, ip_address: str):
try:
# Log user information
user_info = f'User: {interaction.user.name} (ID: {interaction.user.id})'
logging.info(user_info)
# Make a request to ip-api.com
response = requests.get(
f'http://ip-api.com/json/{ip_address}?fields=status,message,continent,continentCode,country,countryCode,region,regionName,city,district,zip,lat,lon,timezone,offset,isp,org,as,asname,reverse,mobile,proxy,hosting,query')
data = response.json()
# Check if the request was successful
if data['status'] == 'fail':
raise Exception(data.get('message', 'Unknown error'))
# Extract relevant information
country = data.get('country', 'N/A')
city = data.get('city', 'N/A')
region = data.get('regionName', 'N/A')
district = data.get('district', 'N/A')
zip_code = data.get('zip', 'N/A')
latitude = data.get('lat', 'N/A')
longitude = data.get('lon', 'N/A')
timezone = data.get('timezone', 'N/A')
isp = data.get('isp', 'N/A')
org = data.get('org', 'N/A')
as_number = data.get('as', 'N/A')
as_name = data.get('asname', 'N/A')
reverse_dns = data.get('reverse', 'N/A')
mobile = data.get('mobile', 'N/A')
proxy = data.get('proxy', 'N/A')
hosting = data.get('hosting', 'N/A')
# Format and send the response with detailed information
response_msg = (
f'## IP Information for {ip_address}:\n'
f'**Country:** {country}\n'
f'**City:** {city}\n'
f'**Region:** {region}\n'
f'**District:** {district}\n'
f'**Zip Code:** {zip_code}\n'
f'**Latitude:** {latitude}\n'
f'**Longitude:** {longitude}\n'
f'**Timezone:** {timezone}\n'
f'**ISP:** {isp}\n'
f'**Organization:** {org}\n'
f'**AS Number:** {as_number}\n'
f'**AS Name:** {as_name}\n'
f'**Reverse DNS:** {reverse_dns}\n'
f'**Mobile:** {mobile}\n'
f'**Proxy:** {proxy}\n'
f'**Hosting:** {hosting}'
)
# Log the response
logging.info(response_msg)
# Send the response to the user
await interaction.response.send_message(response_msg)
except Exception as e:
await print_error(e, interaction)
@bot.tree.command(name='request', description="Make a request to any API or webpage")
async def make_request(interaction: discord.Interaction, url: str):
try:
# Log user information
user_info = f'User: {interaction.user.name} (ID: {interaction.user.id})'
logging.info(user_info)
# Make the request
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# If the response is JSON, format it nicely
try:
response_data = response.json()
output = f'```json\n{json.dumps(response_data, indent=4)}\n```'
except json.JSONDecodeError:
# If not JSON, display the raw response
output = f'```\n{response.text}\n```'
else:
output = f'Error: {response.status_code} - {response.reason}'
# Log the response
logging.info(output)
# Send the response to the user
await interaction.response.send_message(output)
except Exception as e:
await print_error(e, interaction)
@bot.tree.command(name='reversedns', description="Perform reverse DNS lookup")
async def reversedns_lookup(interaction: discord.Interaction, input_ip: str):
try:
response = requests.get(API_BASE_URL + f'reversedns/?q={input_ip}')
output = f'```\n{response.text}\n```'
await interaction.response.send_message(output)
except Exception as e:
await print_error(e, interaction)
@bot.tree.command(name='dnslookup', description="Perform DNS lookup")
async def dns_lookup(interaction: discord.Interaction, input_domain: str):
try:
response = requests.get(API_BASE_URL + f'dnslookup/?q={input_domain}')
output = f'```\n{response.text}\n```'
await interaction.response.send_message(output)
except Exception as e:
await print_error(e, interaction)
@bot.tree.command(name='hostsearch', description="Search for hosts sharing the same DNS")
async def host_search(interaction: discord.Interaction, input_domain: str):
try:
response = requests.get(API_BASE_URL + f'hostsearch/?q={input_domain}')
output = f'```\n{response.text}\n```'
await interaction.response.send_message(output)
except Exception as e:
await print_error(e, interaction)
@bot.tree.command(name='shareddns', description="Find shared DNS entries")
async def shared_dns(interaction: discord.Interaction, input_dns: str):
try:
response = requests.get(API_BASE_URL + f'findshareddns/?q={input_dns}')
output = f'```\n{response.text}\n```'
await interaction.response.send_message(output)
except Exception as e:
await print_error(e, interaction)
@bot.tree.command(name='whois', description="Perform WHOIS lookup")
async def whois_lookup(interaction: discord.Interaction, input_domain_or_ip: str):
try:
whois_info = dict(whois.whois(input_domain_or_ip))
whois_output = ''
for key, value in whois_info.items():
whois_output += f'{key.replace("_", " ").title()}: {value}\n'
output = f"```{whois_output}```"
await interaction.response.send_message(output.replace("[", "").replace("]", "").replace("'", ""))
except Exception as e:
await print_error(e, interaction)
@bot.tree.command(name='reverseip', description="Perform reverse IP lookup")
async def reverse_ip_lookup(interaction: discord.Interaction, input_ip: str):
try:
response = requests.get(
API_BASE_URL + f'reverseiplookup/?q={input_ip}')
output = f'```\n{response.text}\n```'
await interaction.response.send_message(output)
except Exception as e:
await print_error(e, interaction)
@bot.tree.command(name='aslookup', description="Perform AS lookup")
async def as_lookup(interaction: discord.Interaction, input_ip_or_as: str):
try:
response = requests.get(API_BASE_URL + f'aslookup/?q={input_ip_or_as}')
output = f'```\n{response.text}\n```'
await interaction.response.send_message(output)
except Exception as e:
await print_error(e, interaction)
@bot.tree.command(name='ipgeo', description="Get IP geolocation information")
async def ip_geolocation(interaction: discord.Interaction, input_ip: str):
try:
response = requests.get(API_BASE_URL + f'ipgeo/?q={input_ip}')
output = f'```\n{response.text}\n```'
await interaction.response.send_message(output)
except Exception as e:
await print_error(e, interaction)
@bot.tree.command(name='checkinvite', description="Check Discord invite")
async def check_invite(interaction: discord.Interaction, invite_link: str):
try:
# Extract invite code from the link
invite_code = invite_link.split('/')[-1]
# Make a request to Discord API to get invite information
response = requests.get(f'https://discord.com/api/v9/invites/{invite_code}')
data = response.json()
# Check if the request was successful
if 'guild' in data:
# Extract guild information
guild_info = data['guild']
guild_name = guild_info.get('name', 'Not found')
guild_id = guild_info.get('id', 'Not found')
guild_splash = guild_info.get('splash', 'Not found')
guild_banner = guild_info.get('banner', 'Not found')
guild_description = guild_info.get('description', 'Not found')
guild_icon = guild_info.get('icon', 'Not found')
guild_features = ', '.join(guild_info.get('features', ['Not found']))
guild_verification_level = guild_info.get('verification_level', 'Not found')
guild_vanity_url_code = guild_info.get('vanity_url_code', 'Not found')
guild_nsfw_level = guild_info.get('nsfw_level', 'Not found')
guild_nsfw = guild_info.get('nsfw', 'Not found')
guild_premium_subscription_count = guild_info.get('premium_subscription_count', 'Not found')
# Extract channel information
channel_info = data['channel']
channel_id = channel_info.get('id', 'Not found')
channel_type = channel_info.get('type', 'Not found')
channel_name = channel_info.get('name', 'Not found')
# Format and send the response with invite information
invite_info_msg = (
f'**Guild Name:** {guild_name}\n'
f'**Guild ID:** {guild_id}\n'
f'**Guild Splash:** {guild_splash}\n'
f'**Guild Banner:** {guild_banner}\n'
f'**Guild Description:** {guild_description}\n'
f'**Guild Icon:** {guild_icon}\n'
f'**Guild Features:** {guild_features}\n'
f'**Guild Verification Level:** {guild_verification_level}\n'
f'**Guild Vanity URL Code:** {guild_vanity_url_code}\n'
f'**Guild NSFW Level:** {guild_nsfw_level}\n'
f'**Guild NSFW:** {guild_nsfw}\n'
f'**Guild Premium Subscription Count:** {guild_premium_subscription_count}\n'
f'**Channel ID:** {channel_id}\n'
f'**Channel Type:** {channel_type}\n'
f'**Channel Name:** {channel_name}\n'
f'**Invite URL:** `{invite_link}`'
)
# Log the response
logging.info(invite_info_msg)
# Send the response to the user
await interaction.response.send_message(invite_info_msg)
else:
# If the request was not successful, send an error message
error_msg = "Error retrieving invite info. Please check the invite link and try again."
logging.error(error_msg)
await interaction.response.send_message(error_msg)
except Exception as e:
await print_error(e, interaction)
# Run the bot with the token
bot.run(TOKEN)