发送nmap端口扫描python脚本的结果



我有这个通过nmap模块扫描端口的脚本:

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 : %ststate : %s' % (port, nmScan[host][proto][port ['state']))

得到结果后,我需要发送它(例如通过curl发送到slack或类似的地方进行工作聊天(我该如何以更好的方式做到这一点

我计划把这个脚本放在cron上,它会扫描打开的端口,并每天在工作聊天中发送结果。

您可以使用requests库向通道发送请求。并不是每个应用程序都支持这一点,但既然你提到了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()   

最新更新