我的目标是构建一个数据包捕获分析器:
输入:一个pcap (或任何捕获文件)。该文件可能有数百/数千个数据包。
output:关于流量流的大量信息
- 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
解决这个问题的一个显而易见的方法是:
我正计划为此使用替罪羊( python库)。
在我进入实现之前,我很想了解解决这个问题的其他可能方法:
我非常精通Python和C,尽管我对其他可能的选项持开放态度。
更新:10/11月:我发现:https://github.com/vichargrave/espcap是我想要做的事情的一个非常有用的开端。
发布于 2017-11-09 08:36:31
我建议你用皮斯高克。这是特沙克的包装纸。它还支持所有的t鲨过滤器,解码器库,.而且使用起来很容易!这是一个很好的解析.pcap文件的包,也是livecapturing的一个很好的包。
https://pypi.python.org/pypi/pyshark
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>]
https://stackoverflow.com/questions/47197152
复制相似问题