---
title: "Linux抓包以及分析包指令"
author: "BucketLi"
date: "2019-01-22T21:23:17Z"
tags: []
categories: ["操作系统"]
slug: "linux"
draft: false
lastmod: "2019-01-22T21:23:17Z"
id: 2436937
url: "https://bucketli.iteye.com/blog/2436937"
---

**1. 抓包**


> tcpdump -i 网卡名 -s0 -C 10 -Z root -w app_server.pcap


-C 后参数表示文件大小，MB 为单位

**2. 分析包**

安装wireshark 


> yum install wireshark 


接下来就是写指令分析包了，以分析 mysql 3306 端口 response 时间段聚合为例


> tshark -r app_server.pcap -Y " (tcp.srcport eq 3306 and tcp.len>67 )" -o tcp.calculate_timestamps:true -T fields -e frame.number -e frame.time_epoch  -e frame.time_delta_displayed  -e ip.src -e tcp.srcport -e tcp.dstport -e ip.dst -e tcp.time_delta -e tcp.stream -e tcp.len | awk '{ sum=sum+$8; count=count+1 } END{ print sum/count }'