Files
004_comission/hdhdjshxh/task1/scapy_helloworld.py
louiscklaw 118e4a5f39 update,
2025-01-31 19:51:33 +08:00

53 lines
1.2 KiB
Python

from scapy.all import *
packets = rdpcap('PCAP/ay2223_sasp_nmapcatured_1.pcap')
scanned_ports = set() # Set to store unique scanned ports
for pkt in packets:
if pkt.haslayer(TCP):
dst_port = pkt[TCP].dport # Destination port
scanned_ports.add(dst_port)
print("Number of ports scanned:", len(scanned_ports))
from scapy.all import *
# Provide the path to your PCAP file
pcap_file = 'PCAP/ay2223_sasp_nmapcatured_1.pcap'
# Read the PCAP file
packets = rdpcap(pcap_file)
# Create an empty set to store unique destination ports
scanned_ports = set()
for packet in packets:
# Check if it's a TCP packet with destination port information
if TCP in packet and packet[TCP].dport not in scanned_ports:
scanned_ports.add(packet[TCP].dport)
print("Ports that have been scanned:")
for port in sorted(scanned_ports):
print(port)
# PCAP/ay2223_sasp_nmapcatured_1.pcap
from scapy.all import *
# Provide the path to your PCAP file
pcap_file = 'PCAP/ay2223_sasp_nmapcatured_1.pcap'
# Read the PCAP file
packets = rdpcap(pcap_file)
# Retrieve the number of packets in the file
num_packets = len(packets)
print(f"The number of packets in '{pcap_file}' is: {num_packets}")