Nmap HTML scan report - 10 Lines of Python code.

In this post, we are gonna discuss how to quickly scan your network with Nmap and Python. The end result will be the HTML report which you can use it to analyze and store it periodically for compliance purpose.


Nmap is a network scanning tool that will detect open ports and the services running over it.


sudo apt-get install nmap xsltproc

Python Snippet

import shlex, subprocess
def nmap_scan_report():
exec_cmd("nmap -Pn -sV -A --top-ports 2000 -iL input.txt -oX output.xml")
exec_cmd("xsltproc output.xml -o output.html")
def exec_cmd(cmd_str):
args = shlex.split(cmd_str)
pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr = subprocess.PIPE)
out, err = pipe.communicate()
if __name__ == "__main__":

You will get output.html as an HTML report. You can set this script in crontab with input in input.txt.