import ipaddress import os import socket import struct import sys import threading import time # Function to get subnet input from user def get_subnet(): while True: subnet = input("Enter the subnet to target (e.g., 192.168.1.0/24): ") try: # Validate the subnet input ipaddress.ip_network(subnet) return subnet except ValueError: print("Invalid subnet. Please try again.") # Magic string we'll check ICMP responses for MESSAGE = 'PYTHONRULES!' # Class to handle IP headers class IP: def __init__(self, buff=None): # Unpack the IP header fields from the buffer header = struct.unpack('> 4 self.ihl = header[0] & 0xF self.tos = header[1] self.len = header[2] self.id = header[3] self.offset = header[4] self.ttl = header[5] self.protocol_num = header[6] self.sum = header[7] self.src = header[8] self.dst = header[9] # Convert binary IP addresses to human-readable format self.src_address = ipaddress.ip_address(self.src) self.dst_address = ipaddress.ip_address(self.dst) # Map protocol constants to their names self.protocol_map = {1: "ICMP", 6: "TCP", 17: "UDP"} try: self.protocol = self.protocol_map[self.protocol_num] except KeyError: print('No protocol for %s' % self.protocol_num) self.protocol = str(self.protocol_num) # Class to handle ICMP headers class ICMP: def __init__(self, buff): # Unpack the ICMP header fields from the buffer header = struct.unpack('