diff --git a/README.md b/README.md index e89587f..7ebb702 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ # nmap2md -A little utility to convert nmap xml results to markdown tables + +A little utility to convert nmap XML results to markdown tables + +## Usage + +Example which parses nmap XML and outputs Markdown tables + +``` +python nmap2md.py /path/to/file/test.xml -c protocol,port,service,product,version --hs 4 +``` + +## Output example + +#### 74.207.244.221 + +| Protocol | Port | Service | Product | Version | +|----------|------|---------|---------|---------| +| tcp | 22 | ssh | OpenSSH | 5.3p1 Debian 3ubuntu7 | +| tcp | 80 | http | Apache httpd | 2.2.14 | \ No newline at end of file diff --git a/nmap2md.py b/nmap2md.py index 9006c2d..629637b 100644 --- a/nmap2md.py +++ b/nmap2md.py @@ -64,12 +64,14 @@ md += "%s %s\n\n" % ('#' * options.hs, address) md += "| %s |" % " | ".join(map(lambda s: s.title(), columns)) md += "\n" + # Adding +2 for 1 space on left and right sides md += "|%s|" % "|".join(map(lambda s: '-' * (len(s) + 2), columns)) md += "\n" for port_info in result[address]: - # Calculating + # Calculating correct amount of spaces to add some padding and justify content in the cell + # Currently it does not work if content is bigger that the column, in any case it does not break the Markdown view md += "| %s |" % " | ".join(map(lambda s: port_info[s] + (' ' * (len(s) - len(port_info[s]))), columns)) md += "\n"