From 8dc40a7534758acbf613f78b4b4703f84e9e20a7 Mon Sep 17 00:00:00 2001 From: bile0026 Date: Tue, 10 Nov 2020 19:45:38 -0600 Subject: [PATCH] add ssl_verify parameter to disable ssl verification for testing --- .gitignore | 4 ++++ nbs/__init__.py | 38 +++++++++++++++++++++++++++----------- netbox-scanner.conf | 33 +++++++++++++++++---------------- netbox-scanner.py | 1 + samples/nmap-scan.sh | 4 ++-- 5 files changed, 51 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index ec974af..9c41b98 100644 --- a/.gitignore +++ b/.gitignore @@ -106,3 +106,7 @@ venv.bak/ # trash .vscode/ +scans/* +logs/* + +test_api.py \ No newline at end of file diff --git a/nbs/__init__.py b/nbs/__init__.py index 973b5f7..5a5ec79 100644 --- a/nbs/__init__.py +++ b/nbs/__init__.py @@ -1,21 +1,37 @@ import logging +import requests from pynetbox import api class NetBoxScanner(object): - def __init__(self, address, token, tag, cleanup): - self.netbox = api(address, token) - self.tag = tag - self.cleanup = cleanup - self.stats = { - 'unchanged': 0, - 'created': 0, - 'updated': 0, - 'deleted': 0, - 'errors': 0 - } + def __init__(self, address, token, ssl_verify, tag, cleanup): + if (ssl_verify == 'No'): + session = requests.Session() + session.verify = False + self.netbox = api(address, token) + self.netbox.http_session = session + self.tag = tag + self.cleanup = cleanup + self.stats = { + 'unchanged': 0, + 'created': 0, + 'updated': 0, + 'deleted': 0, + 'errors': 0 + } + else: + self.netbox = api(address, token) + self.tag = tag + self.cleanup = cleanup + self.stats = { + 'unchanged': 0, + 'created': 0, + 'updated': 0, + 'deleted': 0, + 'errors': 0 + } def sync_host(self, host): '''Syncs a single host to NetBox diff --git a/netbox-scanner.conf b/netbox-scanner.conf index 5e96598..c6fcd5a 100644 --- a/netbox-scanner.conf +++ b/netbox-scanner.conf @@ -1,26 +1,27 @@ [NETBOX] address = -token = +token = logs = logs/ +ssl_verify = No [NMAP] path = ./ unknown = autodiscovered:netbox-scanner tag = nmap -cleanup = yes +cleanup = no -# [NETXMS] -# address = https://netxms.domain -# username = -# password = -# unknown = autodiscovered:netbox-scanner -# tag = netxms -# cleanup = yes +[NETXMS] +address = https://netxms.domain +username = +password = +unknown = autodiscovered:netbox-scanner +tag = netxms +cleanup = yes -# [PRIME] -# address = https://prime.domain/webacs/api/v4 -# username = -# password = -# unknown = autodiscovered:netbox-scanner -# tag = prime -# cleanup = yes +[PRIME] +address = https://prime.domain/webacs/api/v4 +username = +password = +unknown = autodiscovered:netbox-scanner +tag = prime +cleanup = yes diff --git a/netbox-scanner.py b/netbox-scanner.py index c0aec4d..f331a8b 100644 --- a/netbox-scanner.py +++ b/netbox-scanner.py @@ -87,6 +87,7 @@ if __name__ == '__main__': scanner = NetBoxScanner( netbox['address'], netbox['token'], + netbox['ssl_verify'], nmap['tag'], nmap.getboolean('cleanup') ) diff --git a/samples/nmap-scan.sh b/samples/nmap-scan.sh index 3257971..137060a 100755 --- a/samples/nmap-scan.sh +++ b/samples/nmap-scan.sh @@ -16,7 +16,7 @@ # to look for XML files. ## -NETWORKS="192.168.252.0/24 192.168.3.0/24" +NETWORKS="192.168.3.0/24 192.168.252.0/24" TODAY="$(date +%d.%m.%yT%H:%M:%S%Z)" for net in $NETWORKS; do @@ -25,6 +25,6 @@ for net in $NETWORKS; do nmap "$net" -T4 -sn --host-timeout 30s -oX nmap-"$NETNAME".xml done -python netbox-scanner.py nmap +python3 netbox-scanner.py nmap tar -czvf scans/nmap-"$TODAY".tar.gz *.xml rm -rf *.xml