Skip to content

Instantly share code, notes, and snippets.

@tuxmartin
Last active September 27, 2019 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tuxmartin/5aa7ae488e7397a778ea07cb0f849e91 to your computer and use it in GitHub Desktop.
Save tuxmartin/5aa7ae488e7397a778ea07cb0f849e91 to your computer and use it in GitHub Desktop.
Python NMAP scanner - vystup v HTML tabulce

apt-get install python-nmap

#!/usr/bin/env python
import nmap
import json
f = open('output.html','w')
subnet = '10.123.1.0/24'
ports_list = ['80','443','22','29081','43176','63753','19081','81','8080','8081','8433','8031']
ports = ','.join(str(x) for x in ports_list)
nm = nmap.PortScanner()
nm.scan(hosts=subnet, arguments='-sS -p ' + ports)
f.write ("<html><body><table border='1'>")
f.write ("<tr>")
f.write ("<th>IP</th>")
f.write ("<th>STATE</th>")
for x in ports_list:
f.write ("<th>TCP " + x + "</th>")
f.write ("</tr>")
for host in nm.all_hosts():
f.write ("<tr>")
f.write ("<td>"+ host +"</td>")
f.write ("<td>"+ nm[host].state() +"</td>")
for x in ports_list:
tmp = json.loads( str(nm[host]['tcp'][int(x)]).replace('\'', '"').replace('u"', '"') )
status = str(tmp['state'])
if status == "open":
color = "green"
elif status == "closed":
color = "red"
else:
color = "yellow"
f.write ("<td style='background-color: " + color +"'>"+ status +"</td>")
f.write ("</tr>")
f.write ("</table></body></html>")
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment