MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / start

Method start

actions/scanning.py:1332–1394  ·  view source on GitHub ↗

Starts the network and port scanning process using nmap for efficiency. # MAC/host resolution: SQLITE DB ONLY - CSV logic removed # Reads host data from SQLite database, not from CSV files.

(self)

Source from the content-addressed store, hash-verified

1330 return (self.progress / total) * 100
1331
1332 def start(self):
1333 """
1334 Starts the network and port scanning process using nmap for efficiency.
1335 # MAC/host resolution: SQLITE DB ONLY - CSV logic removed
1336 # Reads host data from SQLite database, not from CSV files.
1337 """
1338 overall_start_time = time.time()
1339
1340 self.logger.info("🚀 STARTING EFFICIENT NETWORK SCAN (nmap network-wide + arp-scan for MACs)")
1341
1342 # Combined discovery and port scan phase
1343 self.logger.info("📡 Running combined host discovery and port scanning")
1344 scan_start = time.time()
1345 self.scan_network_and_collect_hosts()
1346 scan_duration = time.time() - scan_start
1347
1348 # Build ip_data structure from collected hosts (no CSV read)
1349 # MAC/host resolution: SQLITE DB ONLY
1350 class IpDataFromMemory:
1351 """Simple data structure to hold scan results from database."""
1352 def __init__(self, ip_hostname_list):
1353 self.ip_list = [item[0] for item in ip_hostname_list]
1354 self.hostname_list = [item[1] for item in ip_hostname_list]
1355 self.mac_list = [item[2] for item in ip_hostname_list]
1356
1357 self.ip_data = IpDataFromMemory(self.ip_hostname_list)
1358 self.total_ips = len(self.ip_data.ip_list)
1359 self.logger.info(f"✅ Network scan complete: Found {self.total_ips} hosts in {scan_duration:.2f}s")
1360
1361 if self.total_ips == 0:
1362 self.logger.warning("❌ No hosts found!")
1363 return self.ip_data, {}, [], self.csv_result_file, self.netkbfile, set()
1364
1365 # Use nmap port results that were already collected during network scan
1366 self.logger.info(f"📊 Processing port data from nmap results")
1367 self.open_ports = {}
1368
1369 for ip in self.ip_data.ip_list:
1370 # Get ports from nmap results collected during network scan
1371 if hasattr(self, 'nmap_port_data') and ip in self.nmap_port_data:
1372 self.open_ports[ip] = self.nmap_port_data[ip]
1373 if self.open_ports[ip]:
1374 self.logger.info(f"✅ {ip}: {len(self.open_ports[ip])} open ports - {sorted(self.open_ports[ip])}")
1375 else:
1376 self.open_ports[ip] = []
1377 self.logger.debug(f"ℹ️ {ip}: No open ports detected")
1378
1379 # Results summary
1380 self.all_ports = sorted(list(set(port for ports in self.open_ports.values() for port in ports)))
1381 total_open_ports = sum(len(ports) for ports in self.open_ports.values())
1382 hosts_with_ports = len([ip for ip, ports in self.open_ports.items() if ports])
1383
1384 overall_duration = time.time() - overall_start_time
1385
1386 self.logger.info(f"🎉 SCAN COMPLETE!")
1387 self.logger.info(f" 📈 Total duration: {overall_duration:.2f}s")
1388 self.logger.info(f" 🎯 Hosts discovered: {self.total_ips}")
1389 self.logger.info(f" 🔌 Total open ports found: {total_open_ports}")

Callers 1

scanMethod · 0.95

Calls 8

IpDataFromMemoryClass · 0.85
infoMethod · 0.80
warningMethod · 0.80
debugMethod · 0.80
setFunction · 0.50
valuesMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected