首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >分析数据包捕获:正确的方法是什么?

分析数据包捕获:正确的方法是什么?
EN

Stack Overflow用户
提问于 2017-11-09 08:27:50
回答 1查看 725关注 0票数 0

我的目标是构建一个数据包捕获分析器:

输入:一个pcap (或任何捕获文件)。该文件可能有数百/数千个数据包。

output:关于流量流的大量信息

代码语言:javascript
运行
复制
- How many TCP streams?
- How many UDP streams?
- For a given client (source IP):
     o How many TCP connections were opened
     o How many concurrent TCP connections were opened.
     o What was the longest and shortest session
     o What is the re-transmission ratio for a given stream?
- Given a protocol (say HTTP) identify how many streams had this protocol.
- etc

解决这个问题的一个显而易见的方法是:

  1. 读取捕获并将捕获的数据存储在所选的数据结构中。
  2. 对于上述每个查询,编写专门的函数来收集数据(即解析所有流,捕获统计数据)
  3. 转储输出。

我正计划为此使用替罪羊( python库)。

在我进入实现之前,我很想了解解决这个问题的其他可能方法:

  1. 还有其他的框架工程/库可以让工作更容易吗?
  2. 是否有一种完全不同的方法可以利用基于AI/ML的框架。我以前没有AI/ML的经验。
  3. 实现一个框架的最佳方法是什么?在这个框架中,我可以问几个关于数据集的问题,并实现函数来回答这些问题?

我非常精通Python和C,尽管我对其他可能的选项持开放态度。

更新:10/11月:我发现:https://github.com/vichargrave/espcap是我想要做的事情的一个非常有用的开端。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-09 08:36:31

我建议你用皮斯高克。这是特沙克的包装纸。它还支持所有的t鲨过滤器,解码器库,.而且使用起来很容易!这是一个很好的解析.pcap文件的包,也是livecapturing的一个很好的包。

https://pypi.python.org/pypi/pyshark

代码语言:javascript
运行
复制
 import pyshark
cap = pyshark.FileCapture('/root/log.cap')
cap
>>> <FileCapture /root/log.cap>
print cap[0]
Packet (Length: 698)
Layer ETH:
        Destination: BLANKED
        Source: BLANKED
        Type: IP (0x0800)
Layer IP:
        Version: 4
        Header Length: 20 bytes
        Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
        Total Length: 684s
        Identification: 0x254f (9551)
        Flags: 0x00
        Fragment offset: 0
        Time to live: 1
        Protocol: UDP (17)
        Header checksum: 0xe148 [correct]
        Source: BLANKED
        Destination: BLANKED
  ...
dir(cap[0])
['__class__', '__contains__', '__delattr__', '__dict__', '__dir__', '__doc__', '__format__', '__getattr__', '__getattribute__', '__getitem__', '__getstate__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_packet_string', 'bssgp', 'captured_length', 'eth', 'frame_info', 'gprs-ns', 'highest_layer', 'interface_captured', 'ip', 'layers', 'length', 'number', 'pretty_print', 'sniff_time', 'sniff_timestamp', 'transport_layer', 'udp']
cap[0].layers
[<ETH Layer>, <IP Layer>, <UDP Layer>, <GPRS-NS Layer>, <BSSGP Layer>]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47197152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档