Python 3.x | Discord Bot | Multi-Line Message Problem
Verfasst: Mittwoch 2. August 2017, 13:40
Hallo, ich habe vor kurzen angefangen einen Discord Python bot zu schreiben mit der discord.py lib, darauf hin wollte ich mit der python-nmap lib einen "Port Scanner" schreiben der das Ergebnis in den Discord schreibt.
"Port Scanner Teil"
"Ausgabe"
Das Problem ist das ich es nicht über print ausgeben kann sondern ich muss es über tun.
Und jetzt weiß ich nicht wie ich das anstellen soll.
Mit der oben gezeigte version bekomme ich als output:
{'nmap': {'command_line': 'nmap -oX - -p 80 -sV x.x.x.x', 'scaninfo': {'tcp': {'method': 'syn', 'services': '80'}}, 'scanstats': {'timestr': 'Wed Aug 2 14:27:48 2017', 'elapsed': '2.44', 'uphosts': '1', 'downhosts': '0', 'totalhosts': '1'}}, 'scan': {'x.x.x.x': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': 'x.x.x.x'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}, 'tcp': {80: {'state': 'filtered', 'reason': 'no-response', 'name': 'http', 'product': '', 'version': '', 'extrainfo': '', 'conf': '3', 'cpe': ''}}}}}
Ich brauche :
----------------------------------------------------
Host : x.x.x.x
State : up
----------
Protocol : tcp
port : 80 state : filtered
----------------------------------------------------
Ich bedanke mich schonmal im voraus, für eure ideen ^^
Discord.py = https://github.com/Rapptz/discord.py
python-nmap = https://github.com/johanlundberg/python-nmap
"Port Scanner Teil"
Code: Alles auswählen
# Imports
#####################################
import nmap
#####################################
#ENV
##########################################################################################
nm = nmap.PortScanner()
nmapout = ("")
##########################################################################################
def nmaps(ip, portr):
global nmapout
try:
nm.scan(ip, portr)
for host in nm.all_hosts():
print('----------------------------------------------------')
print('Host : %s (%s)' % (host, nm[host].hostname()))
print('State : %s' % nm[host].state())
for proto in nm[host].all_protocols():
print('----------')
print('Protocol : %s' % proto)
lport = list(nm[host][proto].keys())
lport.sort()
for port in lport:
print('port : %s\tstate : %s' % (port, nm[host][proto][port]['state']))
print("----------------------------------------------------")
except:
print("O.o, fucking errors (ノಠ益ಠ)ノ彡┻━┻")
"Ausgabe"
Code: Alles auswählen
@dis_bot.command(aliases=["nscan", "nmap"])
async def nmap_module(*args):
pymap.nmaps(*args)
return await dis_bot.say(pymap.nmapout)
Code: Alles auswählen
return await dis_bot.say()
Und jetzt weiß ich nicht wie ich das anstellen soll.
Mit der oben gezeigte version bekomme ich als output:
{'nmap': {'command_line': 'nmap -oX - -p 80 -sV x.x.x.x', 'scaninfo': {'tcp': {'method': 'syn', 'services': '80'}}, 'scanstats': {'timestr': 'Wed Aug 2 14:27:48 2017', 'elapsed': '2.44', 'uphosts': '1', 'downhosts': '0', 'totalhosts': '1'}}, 'scan': {'x.x.x.x': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': 'x.x.x.x'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}, 'tcp': {80: {'state': 'filtered', 'reason': 'no-response', 'name': 'http', 'product': '', 'version': '', 'extrainfo': '', 'conf': '3', 'cpe': ''}}}}}
Ich brauche :
----------------------------------------------------
Host : x.x.x.x
State : up
----------
Protocol : tcp
port : 80 state : filtered
----------------------------------------------------
Ich bedanke mich schonmal im voraus, für eure ideen ^^
Discord.py = https://github.com/Rapptz/discord.py
python-nmap = https://github.com/johanlundberg/python-nmap