diff options
| author | Oleg Pykhalov <go.wigust@gmail.com> | 2018-12-01 05:12:30 +0300 |
|---|---|---|
| committer | Oleg Pykhalov <go.wigust@gmail.com> | 2019-01-02 11:49:33 +0300 |
| commit | d857f107f9835459ea13d2fa6be68415ea1d5b51 (patch) | |
| tree | 35df1712b1d4d0a92f9fc253ce00fdee9b1ff80f | |
| download | python-nmap2json-d857f107f9835459ea13d2fa6be68415ea1d5b51.tar.gz | |
| -rw-r--r-- | guix.scm | 50 | ||||
| -rw-r--r-- | nmap2json/__init__.py | 0 | ||||
| -rw-r--r-- | nmap2json/__main__.py | 17 | ||||
| -rw-r--r-- | setup.py | 16 |
4 files changed, 83 insertions, 0 deletions
diff --git a/guix.scm b/guix.scm new file mode 100644 index 0000000..4bc2d16 --- /dev/null +++ b/guix.scm @@ -0,0 +1,50 @@ +;; Copyright © 2019 Oleg Pykhalov <go.wigust@gmail.com> +;; Released under the GNU GPLv3 or any later version. + +(use-modules (ice-9 popen) + (ice-9 rdelim) + (guix build utils) + (guix gexp) + (guix git-download) + (guix packages) + (guix build-system python) + (gnu packages bash) + (gnu packages python) + (gnu packages admin) + (gnu packages xml) + (guix packages) + ((guix licenses) #:prefix license:)) + +(define %source-dir (dirname (current-filename))) + +(define (git-output . args) + "Execute 'git ARGS ...' command and return its output without trailing +newspace." + (with-directory-excursion %source-dir + (let* ((port (apply open-pipe* OPEN_READ "git" args)) + (output (read-string port))) + (close-port port) + (string-trim-right output #\newline)))) + +(define (current-commit) + (git-output "log" "-n" "1" "--pretty=format:%H")) + +(let ((commit (current-commit))) + (package + (name "nmap2json") + (version (string-append "0.1" + "-" (string-take commit 7))) + (source (local-file %source-dir + #:recursive? #t + #:select? (git-predicate %source-dir))) + (build-system python-build-system) + (inputs + `(("nmap" ,nmap) + ("python" ,python) + ("python-xmltodict" ,python-xmltodict))) + (synopsis "") + (description "") + (home-page "") + (license license:gpl3+))) + +;;; guix.scm ends here 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()) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..fa80bee --- /dev/null +++ b/setup.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +from distutils.core import setup + +setup(name='nmap2json', + version='0.1', + description='Nmap scan host ports and print as JSON', + author='Oleg Pykhalov', + author_email='go.wigust@gmail.com', + url='https://gitlab.com/wigust/nmap2json', + packages=['nmap2json'], + entry_points={'console_scripts': ['nmap2json = nmap2json.__main__:main']}, + install_requires=[ + 'xmltodict' + ] +) |
