File: test-copy-icmp.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 (40 lines) | stat: -rwxr-xr-x 806 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python

# icmp.py: Demonstrate UDP header decodes
# Copyright (C) 2015, Nevil Brownlee, U Auckland | WAND

from plt_testing import *

from array import *

#icmp_types = {}  # Empty Dictionary
icmp_array = array('i', [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])

out_uri = 'pcapfile:icmp-sample-out.pcap'
of = plt.output_trace(out_uri)
of.start_output()

t = get_example_trace('icmp-sample.pcap')
n = 0

for pkt in t:
    n += 1

    icmp = pkt.icmp
    if not icmp:
        continue

    it = icmp.type
    icmp_array[it] += 1   

    if icmp_array[it] <= 4:
        of.write_packet(pkt)

t.close();  of.close_output()

test_println("%d packets examined\n" % (n), get_tag())

test_println(str(icmp_array), get_tag())

for j in range(0, 12):
   test_println("%2d: %6d" % (j, icmp_array[j]), get_tag())