Send the results of nmap ports scanning python script
I have this script for scanning ports by nmap module:
import nmap
nmScan = nmap.PortScanner()
nmScan.scan('127.0.0.1', '21-443')
for host in nmScan.all_hosts():
print('Host : %s (%s)' % (host, nmScan[host].hostname()))
print('State : %s' % nmScan[host].state())
for proto in nmScan[host].all_protocols():
print('----------')
print('Protocol : %s' % proto)
lport = nmScan[host][proto].keys()
sorted(lport)
for port in lport:
print ('port : %s\tstate : %s' % (port, nmScan[host][proto][port ['state']))
After getting the result I need to send it (by curl for example to working chat in slack or someth. like that) How I can do that in the better way?
I'm planning to put this script to cron and it will scanning open ports and sent the result in working chat every day.
You could use the requests
library to send a request to the channel. Not every app might support this, but since you mentioned Slack:
requests.post('https://slack.com/api/chat.postMessage', {
'token': "your_slack_token",
'channel': "your_slack_channel",
'text': "your text",
'icon_emoji': "icon_emoji",
'username': "your_username",
'blocks': {#some blocks here}
}).json()