pcap のノード毎振り分け
環境
virtualbox / ubuntu1604LTS / mem 4GB / 2cores
tshark version 2以降
前提
/NFS/work/pcap 配下にpcapファイルがたくさんある
ipv6非対応
RAMDISK作成
sudo vi /etc/fstab
tmpfs /ramdisk tmpfs rw,size=1G,x-gvfs-show 0 0
NFS上のpcapファイルを各ノード(Endpoint)で別ファイルに分割
(テンポラリとしてRAMDISK利用)
touch ~/bin/capbynode.sh chmod +x ~/bin/capbynode.sh
vi ~/bin/capbynode.sh
#!/bin/bash # ./capbynode.sh # for tshark ver2 INPUTDIR=/NFS/work/pcap OUTDIR=/NFS/work/pcap/nodes RAMDISK=/ramdisk LIST_PCAP=${RAMDISK}/list_pcap.txt LIST_ENDPOINTS=${RAMDISK}/list_endpoints.txt # output pcap file list ls -1tr ${INPUTDIR}/*.pcap > ${LIST_PCAP} cat ${LIST_PCAP} | while read FILE_PCAP do # clear RAMDISK pcap file rm -f ${RAMDISK}/*pcap # copy from INPUTDIR to RAMDISK echo "---- FILE_PCAP = ${FILE_PCAP} ----" cp -v ${FILE_PCAP} ${RAMDISK}/ cd ${RAMDISK} INPUT_FILE=`ls -1tr *pcap | tail -1` # output endpoints echo "`date -R` : output endpoints start FILE=${INPUT_FILE}" tshark -r ${INPUT_FILE} -q -z endpoints,ipv4 | grep ^[0-9] | awk '{print $1}' > ${LIST_ENDPOINTS} echo "`date -R` : output endpoints complete FILE=${INPUT_FILE}" echo "${LIST_ENDPOINTS} : `cat ${LIST_ENDPOINTS} | wc -l` lines" cat ${LIST_ENDPOINTS} | while read IPADDR do echo "`date -R` : input_file = ${INPUTFILE} ,ipaddr = ${IPADDR} ###" tcpdump -r ${INPUT_FILE} -w ${OUTDIR}/${INPUT_FILE}_${IPADDR}.pcap host ${IPADDR} > /dev/null 2>&1 done done
NFS上の各ノード毎のpcapファイルから任意のアドレスのpcapをマージ
touch ~/bin/merge-nodes.sh chmod +x ~/bin/merge-nodes.sh
vi ~/bin/merge-nodes.sh
#!/bin/bash # mergecap by nodes # merge-nodes.sh [ip-address] INPUTDIR="/NFS/work/pcap/nodes" IPADDR=$1 INFILES=`ls -1tr ${INPUTDIR}/*_${IPADDR}.pcap | tr -s '\n' ' '` mergecap -w ./merge_${IPADDR}.pcap ${INFILES}