代码拉取完成,页面将自动刷新
同步操作将从 现任明教教主-乾颐堂/Python_Netflow 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python3
# -*- coding=utf-8 -*-
# 本脚由亁颐堂现任明教教主编写,用于乾颐盾Python课程!
# 教主QQ:605658506
# 亁颐堂官网www.qytang.com
# 教主技术进化论拓展你的技术新边疆
# https://ke.qq.com/course/271956?tuin=24199d8a
import logging
import sys
import socketserver
from collector_v9 import ExportPacket, createdb
logging.getLogger().setLevel(logging.INFO)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(message)s')
ch.setFormatter(formatter)
logging.getLogger().addHandler(ch)
class SoftflowUDPHandler(socketserver.BaseRequestHandler):
# We need to save the templates our NetFlow device
# send over time. Templates are not resended every
# time a flow is sent to the collector.
TEMPLATES = {}
@classmethod
def get_server(cls, host, port):
logging.info("Listening on interface {}:{}".format(host, port))
server = socketserver.UDPServer((host, port), cls)
return server
def handle(self):
data = self.request[0]
host = self.client_address[0]
s = "Received data from {}, length {}".format(host, len(data))
logging.debug(s)
# 使用类ExportPacket处理数据,并返回实例export,这是整个处理的开始!
export = ExportPacket(data, self.TEMPLATES)
# 把实例export(类ExportPacket)中的属性templates更新到类SoftflowUDPHandler的属性templates,用于保存模板数据
self.TEMPLATES.update(export.templates)
s = "Processed ExportPacket with {} flows.".format(export.header.count)
logging.debug(s)
if __name__ == "__main__":
createdb()
server = SoftflowUDPHandler.get_server('0.0.0.0', 9999)
logging.getLogger().setLevel(logging.DEBUG)
try:
logging.debug("Starting the NetFlow listener")
server.serve_forever(poll_interval=0.5)
except (IOError, SystemExit):
raise
except KeyboardInterrupt:
raise
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。