分布式网络包嗅探和处理框架。
netdumplings的Python项目详细描述
分布式网络包嗅探和处理框架。
有关详细信息,请参见documentation,以及netmomo和packscape 使用Net饺子作为其 后端。Python3.6或更高版本是必需的。
安装
pip install netdumplings
分布式包嗅探?
net饺子允许您在任意数量的主机上运行多个包嗅探器。 那些嗅探者——叫做dumpling kitchens——通过任何嗅探网络 包到您的python代码进行处理。您的python代码实现为 名为dumpling chefs的类,使用网络包生成 饺子。饺子里的东西完全由你决定,但通常 描述嗅探网络数据包中包含的信息。
饺子大厨做的饺子是从饺子厨房送来的 发送到单个dumpling hub,该hub将它们转发到任何连接的 dumpling eaters用于显示或任何其他类型的处理,或 形象化。
显示了厨房、厨师、饺子、hub和eaters。 下面。你用绿色(厨师和食客)和网饺子写小片 剩下的:
饺子是通过网络在厨房、中心和食客之间发送的。
饺子长什么样?
饺子只是json数据。下面的饺子是厨师做的 为每次DNS查找生成一个饺子。
{"metadata":{"chef":"DNSLookupChef","creation_time":1515990765.925951,"driver":"packet","kitchen":"default_kitchen"},"payload":{"lookup":{"hostname":"myspace.com","when":1515990721.147}}}
"payload"部分由饺子厨师和 "metadata"当饺子发送到 厨房旁边的中心。
饺子厨师示例
下面的饺子厨师为每次DNS查找创建一个饺子(请参见 上面的饺子例子)。
importtimeimportnetdumplingsclassDNSLookupChef(netdumplings.DumplingChef):defpacket_handler(self,packet):# The incoming packet is a scapy packet object.# https://scapy.readthedocs.io# Ignore packets that we don't care about.ifnotpacket.haslayer('DNS'):return# Determine the name of the host that was looked up.dns_query=packet.getlayer('DNS')query=dns_query.fields['qd']hostname=query.qname.decode('utf-8')# Generate a dumpling payload from the DNS lookup.dumpling_payload={'lookup':{'hostname':hostname,'when':time.time(),}}# The handler is returning a dict, which will be automatically# converted into a dumpling and sent to nd-hub, which will then# forward it on to all the eaters.returndumpling_payload
吃饺子的例子
下面的食客打印每个从 nd-hub。
importjsonimportnetdumplingsclassPrinterEater(netdumplings.DumplingEater):asyncdefon_connect(self,hub_uri,websocket):print(f'Connected to nd-hub at {hub_uri}')print('Waiting for dumplings...\n')asyncdefon_dumpling(self,dumpling):# The given dumpling is a netdumplings.Dumpling instance.dumpling_printable=json.dumps(dumpling.payload,indent=4)print(f'{dumpling_printable}\n')defdumpling_printer():eater=PrinterEater()eater.run()if__name__=='__main__':dumpling_printer()
更多信息
有关详细信息,请参见documentation。