source: swig/python/check.py @ b49ea36

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since b49ea36 was 47de0aa, checked in by Daniel Lawson <dlawson@…>, 15 years ago
  • Cosmetic changes to trace_help() output
  • inclusion of some m4 handlers to deal with swig and python, lifted from http://autoconf-archive.cryp.to/. These are GPLd, which needs to be taken into account if libtrace licensing changes!
  • updated the swig bindings for python. Mostly api compliant now. Still possibly a memory leak to do with displaying ip addresses - I haven't touched this particular part of the code yet.
  • Property mode set to 100755
File size: 1.0 KB
Line 
1#!/usr/bin/python
2import sys
3sys.path.append('/usr/local/lib/python2.4/site-packages/libtrace')
4import libtrace
5
6trace = libtrace.Trace(sys.argv[1])
7
8if trace.trace_is_err():
9        print "Trace failed: %s" % trace.trace_get_err()
10        sys.exit()
11print "trace=",trace
12
13
14packet = libtrace.Packet()
15
16print "packet=",packet
17count = 0
18
19filter = libtrace.Filter("tcp")
20print "filter=",filter
21
22ret=trace.trace_start()
23
24if ret < 0:
25        print "Trace failed to start with error %s " % ret
26        sys.exit()
27
28while 1:
29        trace.trace_read_packet(packet)
30        if not packet:
31                break
32
33        ippacket = packet.trace_get_ip()
34        if not ippacket:
35                continue
36
37        count += 1
38        if count % 10000 == 0:
39                print count
40
41        tcppacket = packet.trace_get_tcp()
42        if not tcppacket:
43                continue
44
45        if not packet.trace_apply_filter(filter):
46                continue
47       
48        src = packet.trace_get_source_port()
49        dst = packet.trace_get_destination_port()
50        if packet.trace_get_server_port(4,src,dst) == 0:
51                print ippacket.ip_src,':',src,'->',ippacket.ip_dst,':',dst
52        else:   
53                print ippacket.ip_dst,':',dst,'<-',ippacket.ip_src,':',src
54
Note: See TracBrowser for help on using the repository browser.