1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
import dpkt, pcap

def ip_decode(p):
   return ".".join(["%d" % ord(x) for x in str(p)])

def main(argv):
    iface_name = "eth2"  # Here set your listening interface
    pc = pcap.pcap(iface_name)
    pc.setfilter('tcp dst port 80')

    for ts,pkt in pc:

        eth = dpkt.ethernet.Ethernet(pkt)
        ip = eth.data
        tcp = ip.data

        if tcp.dport == 80 and len(tcp.data) > 0:
            try :
                http = dpkt.http.Request(tcp.data)
            except dpkt.dpkt.NeedData:
                continue
            except dpkt.dpkt.UnpackError:
                continue
        else:
            continue

        #print http.method
        print "http://" + "%s" % ip_decode( ip.dst ) + http.uri

if __name__ == "__main__":
    main(sys.argv)