import scapy.
all as scapy
import argparse
# Define the command line arguments
parser = argparse.ArgumentParser(description="Perform a ping sweep on a local
network.")
parser.add_argument("-r", "--range", help="The IP address range to scan (e.g.
192.168.1.0/24)", required=True)
parser.add_argument("-t", "--timeout", help="The timeout for each ping packet (in
seconds)", type=int, default=1)
parser.add_argument("-v", "--verbose", help="Print detailed information about the
scan", action="store_true")
args = parser.parse_args()
# Define the IP range to scan
ip_range = args.range
# Define the ICMP ping packet
ping_packet = scapy.IP(dst=ip_range) / scapy.ICMP()
# Send the ICMP ping packets and record the responses
try:
responses = scapy.srp(ping_packet, timeout=args.timeout, verbose=args.verbose)
except scapy.layers.inet.IPError as e:
print(f"Error: {e}")
exit()
# Print the IP addresses of the hosts that responded
if responses:
for response in responses[0]:
print(response[1].src)
else:
print("No hosts responded to the ping sweep.")