parsing - Python dpkt with pcap - how can I print the packet data? -


i want print out packet data pcap file. code below stores packet data in array can't figure out how print each element of array , split data there. loop on array returns error.

import dpkt import socket  f = open('test.pcap', 'r') pcap = dpkt.pcap.reader(f)  info = []  ts, buf in pcap:      eth = dpkt.ethernet.ethernet(buf)      if not hasattr(eth, 'ip'):         continue     info.append(eth.ip)  f.close()  print info 

it not clear want print. depends on looking for. if want print tcp data, here how it:

import dpkt f = open('test.pcap') pcap = dpkt.pcap.reader(f) ts, buf in pcap:     eth = dpkt.ethernet.ethernet(buf)     ip = eth.data     tcp = ip.data 

if want print data in higher layer, can extend above example so. http, example, follows:

import dpkt  f = open('test.pcap') pcap = dpkt.pcap.reader(f)  ts, buf in pcap:     eth = dpkt.ethernet.ethernet(buf)     ip = eth.data     tcp = ip.data     if tcp.dport == 80:         http = dpkt.http.request(tcp.data)         print http.data 

for more details, see example here, or examples in dpkt project.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -