File: test-IPflow.py

package info (click to toggle)
python-libtrace 1.6%2Bgit20161027-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,124 kB
  • ctags: 1,357
  • sloc: ansic: 6,890; python: 3,228; makefile: 70; sh: 49
file content (48 lines) | stat: -rwxr-xr-x 1,027 bytes parent folder | download | duplicates (5)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python

# Thu, 13 Mar 14 (PDT)
# ip6.py:  Demonstrate IPv6 objects
# Copyright (C) 2014, Nevil Brownlee, U Auckland | WAND

import plt
import natkit

def test_uri(uri):
    t = plt.trace(uri)
    t.start()

    nip = n = 0
    for pkt in t:
        n += 1
        print "n = %d" % n
        try:
            ipf = natkit.IPflow(pkt)
        except:
            print "probably not an IP packet"
            continue

        nip += 1

        print "%5d: %d %3d  %5d %5d  %s  %s" % (n,  # v6
           ipf.version, ipf.proto, ipf.src_port, ipf.dst_port,
           ipf.src_prefix, ipf.dst_prefix)

        fwd = ipf.fwd_key
        print "fwd =",
        for b in fwd:
            print " %02x" % ord(b),

        rev = ipf.rev_key
        print "\nrev =",
        for b in rev:
            print " %02x" % ord(b),
        print

        if nip == 4:
            break

    t.close()

pcap_dir = '../../doc/examples'
test_uri('pcapfile:'+pcap_dir+'/anon-v4.pcap')
test_uri('pcapfile:'+pcap_dir+'/anon-v6.pcap')