-
-
Notifications
You must be signed in to change notification settings - Fork 126
scanning.py
infinition edited this page Jul 5, 2024
·
1 revision
This document describes the detailed step-by-step process of how the NetworkScanner
class works, including the specific methods, classes, and functions used at each step.
-
Code:
self.scanner = NetworkScanner(self.shared_data)
-
Purpose: Initializes the
NetworkScanner
with shared data.
-
Code:
with self.semaphore: self.scanner.scan()
-
Purpose: Acquires a semaphore to limit the number of concurrent threads and calls the
scan
method to start the scanning process.
-
Purpose: Initializes various attributes such as
shared_data
,logger
,console
,semaphore
, andnmap.PortScanner
.
- Purpose: Main method that coordinates the entire scanning process.
-
Key Steps:
- Set scanner status.
- Call
get_network
to retrieve network information. - Initialize
ScanPorts
and start scanning ports. - Call
update_netkb
to update the network knowledge base. - Optionally call
display_csv
to display results. - Use
LiveStatusUpdater
to update live status and clean scan results.
- Purpose: Retrieves the network's default gateway and subnet.
- Purpose: Retrieves the MAC address for a given IP and hostname.
- Purpose: Prepares necessary CSV files for the scan.
- Purpose: Sorts and writes the scanned results to a CSV file.
- Purpose: Updates the network knowledge base with scan results.
- Purpose: Displays the CSV file content using the Rich library for enhanced visualization.
- Purpose: Initializes attributes including file paths, lists for IP data, and open ports.
- Purpose: Scans the network and writes the results to a CSV file.
-
Key Steps:
- Call
check_if_csv_scan_file_exists
to prepare CSV files. - Use
nmap
to scan the network for live hosts. - Start threads to scan each host.
- Call
- Purpose: Scans a specific host to check if it is alive and retrieves its hostname and MAC address.
- Purpose: Starts the network and port scanning process.
-
Purpose: Initializes the
PortScanner
with the target IP, open ports list, and port ranges.
- Purpose: Uses sockets to check if a specific port is open.
- Purpose: Starts scanning ports within the specified range and additional ports using threads.
- Purpose: Scans a port using a semaphore to limit concurrent threads.
-
Purpose: Initializes the
LiveStatusUpdater
with source and output CSV paths.
- Purpose: Reads the source CSV file into a DataFrame.
- Purpose: Calculates the total number of open ports for alive hosts.
- Purpose: Calculates the total and alive host counts.
- Purpose: Saves the calculated results to the output CSV file.
- Purpose: Updates the live status of hosts and saves the results.
- Purpose: Cleans up old scan result files.
-
Create
NetworkScanner
Instance:scanner = NetworkScanner(shared_data)
-
Start the Scan:
with scanner.semaphore: scanner.scan()
The NetworkScanner
class orchestrates a comprehensive network scanning process, using various helper methods and classes to:
- Retrieve network information.
- Scan the network for live hosts and open ports.
- Update and display scan results.
- Maintain a network knowledge base and live status of hosts.
This detailed breakdown should help in understanding the functioning and usage of the NetworkScanner
class.