[vmchecker-dev] [PATCH] added a udp listener to replace buggy netcat

Alexandru Moșoi brtzsnr at gmail.com
Sat Mar 28 10:16:10 EET 2009


---
 .gitignore |    2 ++
 bin/udp.py |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 bin/udp.py

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..52e4e61
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.pyc
+*.pyo
diff --git a/bin/udp.py b/bin/udp.py
new file mode 100644
index 0000000..c779fa1
--- /dev/null
+++ b/bin/udp.py
@@ -0,0 +1,36 @@
+#! /usr/bin/env python2.5
+# -*- coding: utf-8 -*-
+# vim: set expandtab :
+
+
+from __future__ import with_statement
+
+import SocketServer
+import sys
+
+
+__author__ = 'Alexandru Moșoi <brtzsnr at gmail.com>'
+
+
+class UDPHandler(SocketServer.BaseRequestHandler):
+    def handle(self):
+        sys.stdout.write(self.request[0])
+        sys.stdout.flush()
+
+
+if __name__ == '__main__':
+    if len(sys.argv) == 1 or len(sys.argv) > 4:
+        print >>sys.stderr, 'Simple UDP listener. Dumps datagrams to stdout. Usage:'
+        print >>sys.stderr, '\t%s [host] port - listens on host:port (host defaults to localhost).' % sys.argv[0]
+        sys.exit()
+
+    port = None
+    host = None
+    outp = None
+
+    if len(sys.argv) == 2:  # port
+        host, port = 'localhost', int(sys.argv[1])
+    elif len(sys.argv) == 3:  # host port
+        host, port = sys.argv[1:]
+
+    SocketServer.UDPServer((host, port), UDPHandler).serve_forever()
-- 
1.6.2



More information about the vmchecker-dev mailing list