diff options
Diffstat (limited to 'nmap2json')
| -rw-r--r-- | nmap2json/__init__.py | 0 | ||||
| -rw-r--r-- | nmap2json/__main__.py | 17 |
2 files changed, 17 insertions, 0 deletions
diff --git a/nmap2json/__init__.py b/nmap2json/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/nmap2json/__init__.py diff --git a/nmap2json/__main__.py b/nmap2json/__main__.py new file mode 100644 index 0000000..971ad87 --- /dev/null +++ b/nmap2json/__main__.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +import json +import subprocess +import sys +import xmltodict + +lookup = lambda hosts, ports: subprocess.run(["nmap", "-oX", "-", "-Pn", "--open", "-n", "-p", ports, hosts] + , stdout=subprocess.PIPE).stdout.decode("utf-8") + +port_to_json = lambda port: {"{#PORT}": port["@portid"], + "{#NAME}": port["service"]["@name"]} + +main = lambda: json.dumps({"data": list(map(port_to_json, xmltodict.parse(lookup(sys.argv[1], sys.argv[2]))["nmaprun"]["host"]["ports"]["port"]))}) + +if __name__ == '__main__': + print(main()) |
