Network scanner - Host
Network Host Module for network scanning operations.
This module provides classes for network host representation and handling during network scanning operations. It includes the host state tracking and ICMP packet generation capabilities.
- class codestral_ros2_gen.network_scan.network_host.HostState(value)[source]
Bases:
Enum
Enumeration of possible network host states during scanning.
- INIT
Initial state when host is created
- SENT
ICMP packet has been sent to the host
- RESPONDED
Host has responded to the ICMP packet
- TIMEOUT
Host did not respond within the timeout period
- ERROR
An error occurred during scanning
- class codestral_ros2_gen.network_scan.network_host.NetworkHost(ip_address, icmp_id=None, icmp_seq=1, packet_size=64, logger=None)[source]
Bases:
object
Single host handler for network scanning operations.
This class represents a network host during scanning operations, tracking its state and managing ICMP packet generation and validation.
- Parameters:
ip_address (str)
packet_size (int)
logger (Logger | None)
- __init__(ip_address, icmp_id=None, icmp_seq=1, packet_size=64, logger=None)[source]
Initialize a NetworkHost object.
- Parameters:
ip_address (
str
) – IP address of the hosticmp_id – ICMP identifier (random if None)
icmp_seq – ICMP sequence number (default: 1)
packet_size (
int
) – Size of the ICMP packet in bytes (default: 64)logger (
Optional
[Logger
]) – External logger to use (typically a ROS2 logger)
- property state: HostState
Get the current state of the host.
- Returns:
Current state of the host
- Return type:
- _create_icmp_packet()[source]
Create an ICMP echo request packet.
- Returns:
The ICMP packet ready to be sent
- Return type:
bytes
- Raises:
RuntimeError – If the generated packet size is not equal to provided packet size
- _calculate_checksum(data)[source]
Calculate the checksum for an ICMP packet.
- Parameters:
data (
bytes
) – The data to calculate the checksum for- Returns:
The calculated checksum
- Return type:
int
- handle_response(packet)[source]
Validate ICMP echo reply packet for this host.
- Parameters:
packet (bytes) – The received ICMP packet.
- Return type:
None
- Side Effects:
Updates the host state and response time based on the received packet.
- mark_sent()[source]
Mark the host as having had a packet sent to it.
Records the current time as the send time and updates the state.
- Return type:
None