Skip to content

Instantly share code, notes, and snippets.

@gedsic
Created November 18, 2024 08:44
Show Gist options
  • Select an option

  • Save gedsic/1407350c138096eec574ba0f5641b12b to your computer and use it in GitHub Desktop.

Select an option

Save gedsic/1407350c138096eec574ba0f5641b12b to your computer and use it in GitHub Desktop.
Python and Scapy - Get list of all TCP destination ports occuring in a pcap
from scapy.all import *
from natsort import natsorted
packets = rdpcap('in.pcap')
result = []
for packet in packets:
if TCP in packet:
tcpport = str(packet[TCP].dport)
if tcpport not in result:
result.append(tcpport)
result = natsorted(result)
print('\n'.join(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment