【问题标题】:How to print all destination ports and source ports in the PCAP file?如何打印 PCAP 文件中的所有目标端口和源端口?
【发布时间】:2017-03-07 04:44:06
【问题描述】:
import pyshark
pkts = pyshark.FileCapture("test.pcap")


for p in pkts:
      print

我正在尝试打印 PCAP 文件中的所有目标端口和源端口。我该怎么办?

【问题讨论】:

    标签: python python-2.7 python-3.x packets pyshark


    【解决方案1】:
    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-10
      • 1970-01-01
      • 1970-01-01
      • 2020-06-25
      • 1970-01-01
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多