版權聲明
轉載請與作者聯繫,轉載時請務必標明文章原始出處和作者信息及本聲明。
|
|
|
微信掃瞄二維碼進入 Netkiller 微信訂閲號 QQ群:128659835 請註明“讀者” |
本程序用於收集,防火牆,路由器,交換機等日誌
logging enable logging timestamp logging trap warnings logging host inside 172.16.0.5 logging facility local0
172.16.0.5 改為你的syslog伺服器地址
*注意:python版本必須3.0以上
chmod 700 syslogd
./syslogd
#!/srv/python/bin/python3 # -*- encoding: utf-8 -*- # Cisco ASA Firewall - Syslog Server by neo # Author: neo<neo.chen@live.com> import logging import socketserver import threading LOG_FILE = '/var/log/asa5550.log' logging.basicConfig(level=logging.INFO, format='%(message)s', datefmt='', filename=LOG_FILE, filemode='a') class SyslogUDPHandler(socketserver.BaseRequestHandler): def handle(self): data = bytes.decode(self.request[0].strip()) socket = self.request[1] print( "%s : " % self.client_address[0], str(data)) logging.info(str(data)) # socket.sendto(data.upper(), self.client_address) if __name__ == "__main__": try: HOST, PORT = "0.0.0.0", 514 server = socketserver.UDPServer((HOST, PORT), SyslogUDPHandler) server.serve_forever(poll_interval=0.5) except (IOError, SystemExit): raise except KeyboardInterrupt: print ("Crtl+C Pressed. Shutting down.")