0% found this document useful (0 votes)
15 views1 page

New Text Document

This document is a Python script that performs a ping sweep on a local network using the Scapy library. It accepts command line arguments for the IP address range, timeout for ping packets, and a verbose mode for detailed output. The script sends ICMP ping packets to the specified range and prints the IP addresses of any responding hosts.

Uploaded by

y27276665
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

New Text Document

This document is a Python script that performs a ping sweep on a local network using the Scapy library. It accepts command line arguments for the IP address range, timeout for ping packets, and a verbose mode for detailed output. The script sends ICMP ping packets to the specified range and prints the IP addresses of any responding hosts.

Uploaded by

y27276665
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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.")

You might also like