if isinstance(ip.data, dpkt.tcp.TCP):
    tcp = ip.data
try:
    request = dpkt.http.Request(tcp.data)
except (dpkt.dpkt.NeedData, dpkt.dpkt.UnpackError):
    continue
do_not_fragment = bool(ip.off & dpkt.ip.IP_DF)
more_fragments = bool(ip.off & dpkt.ip.IP_MF)
fragment_offset = ip.off & dpkt.ip.IP_OFFMASK
print('Timestamp: ', str(datetime.datetime.utcfromtimestamp(timestamp)))
print('Ethernet Frame: ', mac_addr(eth.src), mac_addr(eth.dst), eth.type)
print('IP: %s -> %s   (len=%d ttl=%d DF=%d MF=%d offset=%d)' % (inet_to_str
    (ip.src), inet_to_str(ip.dst), ip.len, ip.ttl, do_not_fragment,
    more_fragments, fragment_offset))
print('HTTP request: %s\n' % repr(request))
Parsing pcap files with dpkt (Python)