Agent: Improve loop code in IPScanner._scan_address()

This commit is contained in:
Mike Salvatore 2022-01-23 19:29:40 -05:00
parent e1cf4fa9c2
commit ea0ab309d2
1 changed files with 7 additions and 9 deletions

View File

@ -49,25 +49,23 @@ class IPScanner:
self, addresses: Queue, options: Dict, results_callback: Callback, stop: Event self, addresses: Queue, options: Dict, results_callback: Callback, stop: Event
): ):
logger.debug(f"Starting scan thread -- Thread ID: {threading.get_ident()}") logger.debug(f"Starting scan thread -- Thread ID: {threading.get_ident()}")
icmp_timeout = options["icmp"]["timeout_ms"] / 1000
tcp_timeout = options["tcp"]["timeout_ms"] / 1000
tcp_ports = options["tcp"]["ports"]
try: try:
while not stop.is_set(): while not stop.is_set():
address = addresses.get_nowait() address = addresses.get_nowait()
ip = address.ip logger.info(f"Scanning {address.ip}")
logger.info(f"Scanning {ip}")
icmp_timeout = options["icmp"]["timeout_ms"] / 1000 ping_scan_data = self._puppet.ping(address.ip, icmp_timeout)
ping_scan_data = self._puppet.ping(ip, icmp_timeout) port_scan_data = self._scan_tcp_ports(address.ip, tcp_ports, tcp_timeout, stop)
tcp_timeout = options["tcp"]["timeout_ms"] / 1000
tcp_ports = options["tcp"]["ports"]
port_scan_data = self._scan_tcp_ports(ip, tcp_ports, tcp_timeout, stop)
fingerprint_data = {} fingerprint_data = {}
if IPScanner.port_scan_found_open_port(port_scan_data): if IPScanner.port_scan_found_open_port(port_scan_data):
fingerprinters = options["fingerprinters"] fingerprinters = options["fingerprinters"]
fingerprint_data = self._run_fingerprinters( fingerprint_data = self._run_fingerprinters(
ip, fingerprinters, ping_scan_data, port_scan_data, stop address.ip, fingerprinters, ping_scan_data, port_scan_data, stop
) )
scan_results = IPScanResults(ping_scan_data, port_scan_data, fingerprint_data) scan_results = IPScanResults(ping_scan_data, port_scan_data, fingerprint_data)