xldrx / dpkt

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

dpkt.dpkt.UnpackError: invalid request: '' #96

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. When I type in this line: http = dpkt.http.Request(tcp.data)

What is the expected output? What do you see instead?

I expect the script to run without any errors.

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

Python 2.7. The python script is meant to be cross-platform

Please provide any additional information below.

This is my code:

import dpkt, glob, pcap, socket, time

def delay():
    time.sleep(0.6) # delay execution of python script
    print "\n"

fileName = glob.glob("*.pcap") # finds all matching pathnames specified for 
.pcap files (hardcode for now)
print "Files present:",fileName
print ""

for files in fileName:
    f = open(files)
    print f
    delay()
    pcap = dpkt.pcap.Reader(f) #@UndefinedVariable
    pkt_counter = 0
    pkt_counter_relevant = 0
    pkt_counter_non_relevant = 0

    for ts, buf in pcap:
        pkt_counter += 1

        eth = dpkt.ethernet.Ethernet(buf)

        # check if frame type is an IP packet
        if type(eth.data) == dpkt.ip.IP:

            if pkt_counter > 0:
                pkt_counter_relevant += 1
                last_time = ts
                ip = eth.data
                tcp = ip.data
                src = socket.inet_ntoa(ip.src)
                dst = socket.inet_ntoa(ip.dst)
                srcPort = tcp.sport
                dstPort = tcp.dport

                print "---------------"
                print "- Packet #%d -" % (pkt_counter) 
                print "---------------"
                print "Timestamp:",ts
                print "Bytes:",len(buf)
                print "Source IP/Port:",src,"/",srcPort
                print "Destination IP/Port:",dst,"/",dstPort

                # check if it's a TCP/HTTP protocol
                if dstPort == 80:
                    delay()
                    print "Protocol: TCP/HTTP"
                    delay()
                    http = dpkt.http.Request(tcp.data)

Original issue reported on code.google.com by daw...@un0wn.org on 4 Sep 2012 at 9:43

GoogleCodeExporter commented 9 years ago
Traceback (most recent call last):
    http = dpkt.http.Request(tcp.data) - my script
    self.unpack(args[0]) - dpkt http.py
    raise dpkt.UnpackError('invalid request: %r' % line) - dpkt http.py

Original comment by daw...@un0wn.org on 4 Sep 2012 at 9:45