import nmap
import requests
import json
import os
os.remove("result.json")
def my_scanner(host, port_range):
scan_dict = {}
nmScan = nmap.PortScanner()
nmScan.scan(host, port_range)
for host in nmScan.all_hosts():
#scan_dict['ip'] = ip
scan_dict['Host'] = host
#scan_dict['host_name'] = nmScan[host].hostname()
scan_dict['State'] = nmScan[host].state()
for proto in nmScan[host].all_protocols():
scan_dict[proto] = {}
lport = nmScan[host][proto].keys()
sorted(lport)
for port in lport:
scan_dict[proto][port] = nmScan[host][proto][port]['state']
json_object = json.dumps(scan_dict)
# Writing to sample.json
with open("result.json", "a") as outfile:
outfile.write(json_object)
return
ip_list = ['127.0.0.1','127.0.0.1']
port_range_list = ['21-22']
for host in ip_list:
print(my_scanner(host,'21-22'))
my_file = {
'file' : ('/home/user/any_dir/result.json', open('/home/user/any_dir/result.json', 'rb'), 'json')
}
payload={
"filename":"result.json",
"token":"https://hooks.slack.com/services/**************/**************/**************",
"channels":['#1'],
}
r = requests.post("https://hooks.slack.com/services/******************/****************/****************", params=payload, files=my_file)
Не могу понять в чем дело, бота в слаке я создал, токен также прикрепил. Курлом сообщения отправляются в нужный чат.
Сам скрипт рабочий. Есть идеи?