gpt4 book ai didi

protocols - python dpkt pcap 如何获取协议(protocol)?

转载 作者:行者123 更新时间:2023-12-01 22:30:19 24 4
gpt4 key购买 nike

我有一个实验室,我需要为一个巨大的 pcap 文件的每个数据包找到协议(protocol)。我打算制作一本字典来保存它们,但我的第一步只是使用 dpkt 提取信息。看起来 ip.get_proto 是我想要的,但我遗漏了一些要点。我正在阅读http://www.commercialventvac.com/dpkt.html#mozTocId839997

#!/usr/bin/python
# -*- coding: utf-8 -*-

import dpkt
import socket
import sys
import datetime

import matplotlib.pyplot as ploot
import numpy as arrayNum
from collections import Counter

packets = 0

protocolDist = {}

f = open('bob.pcap')
#f = open('trace1.pcap')
pcap = dpkt.pcap.Reader(f)

print "Maj Version: " , dpkt.pcap.PCAP_VERSION_MAJOR
print "Min Version: " , dpkt.pcap.PCAP_VERSION_MINOR
print "Link Layer " , pcap.datalink()
print "Snap Len: " , pcap.snaplen

# How many packets does the trace contain? Count timestamps

# iterate through packets, we get a timestamp (ts) and packet data buffer (buf)
for ts,buf in pcap:
packets += 1
eth = dpkt.ethernet.Ethernet(buf)
ip = eth.data
# what is the timestamp of the first packet in the trace?
if packets == 1:
first = ts
print "The first timestamp is %f " % (first)
print ip.get_proto
break

# What is the average packet rate? (packets/second)
# The last time stamp
last = ts
print "The last timestamp is %f " % (ts)
print "The total time is %f " % (last - first)
print "There are %d " % (packets)
#print "The packets/second %f " % (packets/(last-first))


# what is the protocol distribution?
# use dictionary

f.close()
sys.exit(0)

最佳答案

查看ip.p它返回一个与协议(protocol)号相对应的数字。例如,UDP 有 17 个。不检查

干杯

关于protocols - python dpkt pcap 如何获取协议(protocol)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29838815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com