add nmap command
This commit is contained in:
parent
2069ca7bbf
commit
7bc24ca6fc
1 changed files with 31 additions and 0 deletions
31
guild2.py
31
guild2.py
|
@ -31,6 +31,8 @@ import distro
|
||||||
print("[" + BLUE + "..." + RESET + "] Importing DuckDuckGo search...")
|
print("[" + BLUE + "..." + RESET + "] Importing DuckDuckGo search...")
|
||||||
from duckduckgo_search import DDGS
|
from duckduckgo_search import DDGS
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import nmap
|
||||||
|
import re
|
||||||
client = guilded.Client()
|
client = guilded.Client()
|
||||||
# Help document
|
# Help document
|
||||||
documentation = """$help - Shows this message.
|
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'))
|
output = (result.stdout.decode('utf-8')+result.stderr.decode('utf-8'))
|
||||||
mess = await message.reply("```\n" + output + "\n```")
|
mess = await message.reply("```\n" + output + "\n```")
|
||||||
print("[" + GREEN + "OK" + RESET + "] '$figlet' executed successfully.")
|
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":
|
elif command[0] == "error":
|
||||||
raise SweeBotTestException("Test Error for SweeBot")
|
raise SweeBotTestException("Test Error for SweeBot")
|
||||||
elif command[0] == "search":
|
elif command[0] == "search":
|
||||||
|
|
Loading…
Reference in a new issue