1
0
Fork 0

add nmap command

This commit is contained in:
Swee 2024-11-09 14:41:51 -08:00
parent 2069ca7bbf
commit 7bc24ca6fc

View file

@ -31,6 +31,8 @@ import distro
print("[" + BLUE + "..." + RESET + "] Importing DuckDuckGo search...")
from duckduckgo_search import DDGS
import subprocess
import nmap
import re
client = guilded.Client()
# Help document
documentation = """$help - Shows this message.
@ -180,6 +182,35 @@ async def on_message(message):
output = (result.stdout.decode('utf-8')+result.stderr.decode('utf-8'))
mess = await message.reply("```\n" + output + "\n```")
print("[" + GREEN + "OK" + RESET + "] '$figlet' executed successfully.")
elif command[0] == "nmap":
if len(command) == 2:
result = subprocess.run(["nmap", "--noninteractive", command[1]], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = result.stdout.decode('utf-8')
ports = []
if output.split("\n")[1][:6] == "Failed":
mess = await message.reply(embed=guilded.Embed(title=":sweebot-fail: Command Failed!",description="Nmap failed to resolve the domain!"))
else:
if len(output.split("\n")) < 8:
mess = await message.reply(embed=guilded.Embed(title=":sweebot-unknown:",description="Nmap ran successfully, but the output is smaller than usual."))
else:
ending = False
for i, j in enumerate(output.split("\n")):
if not ending:
if j[:4] == "PORT":
ending = True
pass
else:
temp = (re.sub(' +', ' ', j)).split(" ")
print(temp)
if j != "":
ports.append(("🟢 " if temp[1] == "open" else "🔴 ") + temp[0] + " (" + temp[2] + ")")
else:
break
mess = await message.reply(embed=guilded.Embed(title=":sweebot-success: Found " + str(len(ports)) +" ports",description="\n".join(ports)))
print("[" + GREEN + "OK" + RESET + "] '$nmap' executed successfully.")
else:
mess = await message.reply(embed=guilded.Embed(title=":sweebot-fail: Invalid arguments",description="Only 1 argument is allowed: $nmap [hostname/IP]"))
elif command[0] == "error":
raise SweeBotTestException("Test Error for SweeBot")
elif command[0] == "search":