guanana 8bfaf2d7d5 netbox-scanner.conf:
Add networks path
netbox-scanner.py:
  Add dir_config option
  Read networks file
networks.txt:
  Move to expected location and added some examples
nmap.py:
  Use of nmap library to simplify nmap scan
requirements.txt:
  Update requirements.txt with nmap library and update other libraries to latest compatible version
2020-12-13 04:45:07 +00:00

34 lines
965 B
Python

import nmap3
class Nmap(object):
def __init__(self, unknown, networks):
self.unknown = unknown
self.networks = networks
self.hosts = list()
self.scan_results = {}
def scan(self):
nmap = nmap3.NmapHostDiscovery() # instantiate nmap object
for item in self.networks:
temp_scan_result = nmap.nmap_no_portscan(item.replace('\n', ''))
self.scan_results = {**self.scan_results, **temp_scan_result}
return self.scan_results
def run(self):
scan_result = self.scan()
scan_result.pop("stats")
scan_result.pop("runtime")
for k,v in scan_result.items():
try:
self.hosts.append((
k,
v['hostname'][0]['name']
))
except (IndexError, KeyError):
self.hosts.append((
k,
self.unknown
))