rnithyanand / dpkt

Automatically exported from code.google.com/p/dpkt
Other
0 stars 0 forks source link

PCAP paser error #81

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. running pcap parser
2.
#!/usr/bin/env python2

import dpkt # Framework for parsing packets, use python 2.6
import sys

try:
    file = open(sys.argv[1], 'rb')
    #print sys.argv[1]
    pcap = dpkt.pcap.Reader(file)
    #print pcap
    lines = 0
    for ts, buf in pcap:
        #print pkts, len(buf)
        eth = dpkt.ethernet.Ethernet(buf)
        ip = eth.data
        tcp = ip.data
        lines = lines +1
    print lines
    if tcp.dport == 80 and len(tcp.data) > 0:
        http = dpkt.http.Request(tcp.data)
        print http.uri

    file.close()

except ValueError:
    print "Could not open file!"

What is the expected output? What do you see instead?
Traceback (most recent call last):
  File "pcapParser.py", line 17, in <module>
    tcp = ip.data
AttributeError: 'str' object has no attribute 'data'

What version of the product are you using? On what operating system?
1.7

Please provide any additional information below.
n/a

Original issue reported on code.google.com by rrpo...@gmail.com on 3 Nov 2011 at 5:12

GoogleCodeExporter commented 9 years ago
Ok, figures this one out.  Now I'm just trying to print all known attributes of 
tcp or udp.  It keeps failing because it finds a none IP based packet.  I need 
a one liner that prints everything except arp.

Original comment by rrpo...@gmail.com on 3 Nov 2011 at 7:26

GoogleCodeExporter commented 9 years ago
Not an issue with dpkt -- closing

Original comment by timur.al...@gmail.com on 17 Mar 2012 at 11:37

GoogleCodeExporter commented 9 years ago
i have a same error. how can i fix this ? 
i m using python 2.7
my operating system  , windows7 64bit

Original comment by engn...@gmail.com on 2 Jul 2012 at 2:30

GoogleCodeExporter commented 9 years ago
my error message is :

if tcp.dport == 80 and len(tcp.data)> 0 :
AttributeError : 'ICMP' object has no attribute 'dport'

Original comment by engn...@gmail.com on 2 Jul 2012 at 2:32

GoogleCodeExporter commented 9 years ago
I have a similar problem running the dpkt tutorial, but the error I get 
involves tcp.dport and str object not having an attribute...

    if tcp.dport == 80 and len(tcp.data) > 0:
AttributeError: 'str' object has no attribute 'dport'

Original comment by agruns...@gmail.com on 29 Jul 2013 at 1:11

GoogleCodeExporter commented 9 years ago
SAMPLE outputfor same issue:
62492
41325
42921
22
62493
41325
42922
22
42923
22
42924
22
Traceback (most recent call last):
  File "C:\Users\aman\parse.py", line 8, in <mod
ule>
    tcp = ip.data
AttributeError: 'str' object has no attribute 'data'

CODE:

import dpkt
import sys
f = open('cap1.pcap','rb')
pcap = dpkt.pcap.Reader(f)
for ts, buf in pcap:
  eth = dpkt.ethernet.Ethernet(buf)
  ip = eth.data
  tcp = ip.data
  print ip.id
  print tcp.sport

Original comment by amanroya...@gmail.com on 2 May 2014 at 5:50