【问题标题】:Find number of udp and tcp packets in .pcap file with scapy使用 scapy 在 .pcap 文件中查找 udp 和 tcp 数据包的数量
【发布时间】:2015-05-26 15:20:50
【问题描述】:

大家好,当我用 scapy 嗅探 .pcap 文件时,我正在尝试找到一些方法来检查我有多少个 tcp 和 udp 数据包。如果你能向我解释一下这样做的方法,我会很高兴。

from scapy.all import *
import time

def main():

path = raw_input("Enter path: ") # .pcap file
packs = rdpcap(path)
option = 0
while (option != 4):

    print "Options: soon "
    option = input("Enter your option: ")
    i = 0
    count = 0
    if(option == 1):
        print "Number of packets: "
        pack_len = len(packs)
        print pack_len
        print "Sniff tome: "
        print time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(packs[0].time))
        print time.strftime("%Y-%m-%d %H:%M:%S",   time.gmtime(packs[pack_len-1].time))

    elif(option == 2):
        pass # HERE I NEED TO CHECK HOW MANY TCP AND UDP PACKETS I HAVE

    elif(option == 3):
        path = raw_input("Enter new path: ")
        packs = rdpcap(path)

if __name__ == "__main__":
    main()

【问题讨论】:

    标签: python scapy sniffing


    【解决方案1】:

    例如,您可以使用“in”命令(抱歉代码混乱,这里已经很晚了):

    for i in range(0, len(packs))
              pkt = packs[1]
              if (TCP in pkt):
                       countTCP+= 1
              elif (UDP in pkt):
                       countUDP+= 1
    

    希望我能正确理解您的问题...如果它有效,请告诉我们。祝你好运!

    【讨论】:

    • 感谢它的工作,但下次使用 [i] 代替 (i) 和 += 用于计数器。
    猜你喜欢
    • 2022-01-21
    • 2022-07-08
    • 1970-01-01
    • 2023-02-08
    • 2018-09-17
    • 2011-11-26
    • 1970-01-01
    • 1970-01-01
    • 2013-12-20
    相关资源
    最近更新 更多