Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add json output option #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Options:
--collection COLLECTION Add records to mongo collection
-H, --hosts Print *nix hosts file format [default].
-R, --raw Print raw collection database
-J, --json Print collection database in JSON format
-I, --insert Performs insert instead of in place update
-S, --snmp Make SNMP calls
-A, --ansible Make Ansible inventory
Expand Down
4 changes: 4 additions & 0 deletions nmap-scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
--collection COLLECTION Add records to mongo collection
-H, --hosts Print *nix hosts file format [default].
-R, --raw Print raw collection database
-J, --json Print collection database in JSON format
-I, --insert Performs insert instead of in place update
-S, --snmp Make SNMP calls
-A, --ansible Make Ansible inventory
Expand All @@ -23,6 +24,7 @@
import datetime
import os
import sys
import json

if os.name == 'posix' and sys.version_info[0] < 3:
import subprocess32 as subprocess
Expand Down Expand Up @@ -223,6 +225,8 @@ def insert(record, col):
print_ansible(records)
elif args["--raw"]:
print_raw(records)
elif args["--json"]:
print(json.dumps(records))

elif args["--mongo-host"]:
url = "mongodb://{host}:{port}/".format(host=args["--mongo-host"], port=args["--mongo-port"])
Expand Down