Created
June 27, 2017 12:38
-
-
Save pbertera/0eddab7f62ee5e69c68b633789115258 to your computer and use it in GitHub Desktop.
Minimal syslog server in Python (working with 2.7 and 3.x)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
try: | |
import socketserver | |
except ImportError: # Python 2: | |
import SocketServer as socketserver | |
import socket | |
import sys | |
class LoggedUDPServer(socketserver.ThreadingMixIn, socketserver.UDPServer): | |
def __init__(self, server_address, RequestHandlerClass): | |
socketserver.UDPServer.__init__(self, server_address, RequestHandlerClass) | |
class UDPHandler(socketserver.BaseRequestHandler): | |
def handle(self): | |
print(self.request[0]) | |
if __name__ == "__main__": | |
if len(sys.argv) == 3: | |
port = int(sys.argv[2]) | |
address = sys.argv[1] | |
server = LoggedUDPServer((address, port), UDPHandler) | |
print("Syslog server listening on UDP %s:%d\n\n" % (address, port)) | |
server.serve_forever() | |
else: | |
print("ERROR: you must specify address and port:") | |
print("%s 192.168.10.33 514" % sys.argv[0]) | |
sys.exit(-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment