import dpkt

# Specify the path to the PCAP file
pcap_file = "Capture_1_Kum.pcap"

# Create a set to store unique server IP addresses
server_ips = set()

try:
    with open(pcap_file, "rb") as file:
        pcap = dpkt.pcap.Reader(file)
        for timestamp, buf in pcap:
            eth = dpkt.ethernet.Ethernet(buf)
            if isinstance(eth.data, dpkt.ip.IP):
                ip = eth.data
                # Extract the source IP address from the IP header (IPv4 only)
                if isinstance(ip.data, dpkt.tcp.TCP):
                    server_ips.add(ip.src)

# Count the number of unique server IP addresses
    num_servers = len(server_ips)

# Print the result
    print(f"Number of servers in the PCAP file: {num_servers}")
except FileNotFoundError:
    print(f"File '{pcap_file}' not found.")
except Exception as e:
    print(f"An error occurred: {e}")
