1
import pyshark
pkts = pyshark.FileCapture("test.pcap")


for p in pkts:
      print

I am trying to print all destination ports and source ports in the PCAP file. How could I do it?

charlesreid1
  • 4,360
  • 4
  • 30
  • 52
Ed S
  • 385
  • 8
  • 31

1 Answers1

5
import pyshark

pkts = pyshark.FileCapture('cap.pcap')

for p in pkts:
    if hasattr(p, 'tcp'):
        print(p.tcp.srcport + ' -- ' + p.tcp.dstport)
    if hasattr(p, 'udp'):
        print(p.udp.srcport + ' -- ' + p.udp.dstport)
zsrkmyn
  • 547
  • 1
  • 5
  • 20