APP下载

网络流量采集与分析系统的实现

2022-04-12龙恒张劲勇吴红梅

计算机时代 2022年4期

龙恒 张劲勇 吴红梅

摘  要: 在使用基于网络的应用或服务的过程中会遇到各种问题,需要使用流量分析工具找出原因才能解决问题。文章阐述了一套流量采集及分析系统的实现过程,重点讲解了数据包的捕获技术及分析方法、后台进程的结构,以及线程之间的交互过程、采用双缓冲区方案实现线程同步以避免出现资源竞争、使用内存预分配技术来提高内存缓冲区数据结构的性能等方面的内容。该系统已实际运行一年多,可以解决网络应用中的常见问题,具有较强的实用性。

关键词: 数据包捕获; 数据包分析; Npcap; 线程同步; 内存预分配

中图分类号:TP311          文献标识码:A     文章编号:1006-8228(2022)04-24-05

Implement of network traffic collection and analysis system

Long Heng Zhang Jinyong Wu Hongmei

(Maoming Polytechnic, Maoming, Guangdong 525000, China)

Abstract: In the process of using network-based applications or services, various problems are encountered, and it is necessary to use traffic analysis tools to find out the reasons and solve these problems. In this paper, the realization process of a set of flow collection and analysis system is expounded. It focuses on the capture technology and analysis method of data packets, the structure of the background process, and the interaction process between threads. The double buffer scheme is used to achieve thread synchronization to avoid resource contention. The memory pre-allocation technique is used to improve the performance of the memory buffer data structure. The system has been in practical use for more than a year. It can solve common problems in network applications, and has strong practicability.

Key words: packet capture; packet analysis; Npcap; thread synchronization; memory pre-allocation

0 引言

随着互联网的普及,很多应用和服务都需要联网才能使用,这些应用和服务在使用过程中会出现各种由于网络原因导致的问题,例如网页加载缓慢、视频播放卡顿、服务不可用等等。管理员需要对网络中的流量数据进行分析,从中获取有用的信息,才能找到并解决问题。

本文详细介绍了一套网络流量采集与分析系统的实现方法,该系统分为前后台两部分,后台进程捕获数据包然后对其进行分解,根据数据包首部字段的值和应用层数据对数据包进行分类并将指定信息保存到数据库中;前端应用负责对保存在数据库中的数据进行统计分析并将结果显示给用户。这套系统难点在于后台的实现,这也是本文關注的重点。

1 数据包捕获技术

本系……

登录APP查看全文