怎样设置tcpdump抓包的缓冲大小值

2024-12-23 12:31:50
推荐回答(2个)
回答1:

你好,你可以试试我这个:
sec=300
while [ 1 ]
do
killall tcpdump
mv ip.packet ip.packet.1
tcpdump -w ip.packet -s 0 tcp or udp &
rrd_data=""
traffic=`tcpdump -r ip.packet.1 src 192.168.0.1 and dst 192.168.0.2 -v | sed -e 's/.*, length: \(.*\))/\1/g' | awk -F " " '{print $1}'| sed -e 's/)//g'| tr '\n' '+'`
traffic=`echo ${traffic}0 | bc`
traffic=`expr $traffic / $sec`
rrd_data=$traffic
echo $rrd_data >1.txt
echo $rrd_data >>2.txt
sleep $sec
done

回答2:

你可以试试这个:

sec=300
while [ 1 ]
do
killall tcpdump
mv ip.packet ip.packet.1
tcpdump -w ip.packet -s 0 tcp or udp &
rrd_data=""
traffic=`tcpdump -r ip.packet.1 src 192.168.0.1 and dst 192.168.0.2 -v | sed -e 's/.*, length: \(.*\))/\1/g' | awk -F " " '{print $1}'| sed -e 's/)//g'| tr '\n' '+'`
traffic=`echo ${traffic}0 | bc`
traffic=`expr $traffic / $sec`
rrd_data=$traffic
echo $rrd_data >1.txt
echo $rrd_data >>2.txt
sleep $sec

done