Version 1.1 with conntrack-tools support
[bwmon.git] / runpipe.py
blob18df93f827ff9c61297b9a73b7d17c39fddb9adc
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 # Copyright 2010 Thomas Perl and Stefan Kögl. All rights reserved.
6 # Developed for a practical course (Large-scaled distributed computing) at the
7 # University of Technology Vienna in the 2010 summer term.
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are met:
12 # 1. Redistributions of source code must retain the above copyright notice,
13 # this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright notice,
16 # this list of conditions and the following disclaimer in the documentation
17 # and/or other materials provided with the distribution.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
22 # EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 from __future__ import absolute_import
33 import os
34 import sys
35 from bwmon.pipe import Pipe, PipeMonitor
37 sys.path.insert(0, os.path.dirname(__file__) or '.')
39 if __name__ == '__main__':
40 if len(sys.argv) > 2:
41 port = newport = int(sys.argv[1])
42 newhost = sys.argv[2]
43 if len(sys.argv) == 4:
44 newport = int(sys.argv[3])
45 pipe = Pipe(port, newhost, newport)
46 monitor = PipeMonitor(pipe)
47 pipe.start()
48 try:
49 monitor.run()
50 except KeyboardInterrupt:
51 pipe.close()
52 print 'Waiting for threads to finish...'
54 else:
55 import sys
56 print >> sys.stderr, '''
57 Usage:
58 runpipe.py <port> <remotehost>
59 runpipe.py <localport> <remotehost> <remoteport>
61 '''