2

私はラボを持っており、巨大な pcap ファイルの各パケットのプロトコルを見つける必要があります。それらすべてを保持する辞書を作成しますが、最初のステップは、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)
4

2 に答える 2

4

Check ip.p プロトコル番号に対応する番号を返します。たとえば、UDP には 17 があります。

乾杯

于 2015-05-27T23:06:33.427 に答える