D
D
Dscarve12022-01-18 14:52:42
Python
Dscarve1, 2022-01-18 14:52:42

How to send the result of the script to the slack chat?

There is a script that scans and displays open ports:

import nmap
import requests
import json

nmScan = nmap.PortScanner()


nmScan.scan('127.0.0.1', '21-2000')


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']))

It is planned to put this script on cron so that it scans daily and, most importantly, sends the results of its work to the slack chat.
How to make sure that the results of the script are sent to the slack chat or at least to your server?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2022-01-18
@SoreMix

Create a new application in Slack: https://api.slack.com/apps/new
Link it to your workspace
Select Incoming Webhooks

https://api.slack.com/apps/%APPID%/incoming-webhooks

Activate
Read the instructions on how to send requests
Click Add New Webhook to Workspace, bind the webhook to the desired channel Send
text via requests
import requests

data = {'text': 'TARGET: target.com\nports: 8080, 443'}
requests.post(WEBHOOK_URL, json=data)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question