Debian Codegraph @

devel-tools/extract-conn-by-uid

raw
1 #! /usr/bin/env bash
2 #
3 # Searches the connection with UID $1 in conn.log, and then extracts
4 # it from trace file $2.
5
6 if [ $# != 2 ]; then
7 echo "usage: `basename $0` <uid> <trace>"
8 exit 1
9 fi
10
11 uid=$1
12 trace=$2
13
14 if [ ! -e conn.log ]; then
15 echo "no conn.log found"
16 exit 1
17 fi
18
19 if [ ! -e $trace ]; then
20 echo "trace $trace not found"
21 exit 1
22 fi
23
24 filter=`awk -v uid=$uid '$2==uid { printf("host %s and port %s and host %s and port %s\n", $3, $4, $5, $6)}' <conn.log`
25
26 if [ "$filter" == "" ]; then
27 echo uid $uid not found in conn.log
28 exit 1
29 fi
30
31 echo filter: $filter
32
33 out=`basename $trace`.$uid
34
35 if echo $trace | grep -q '\.gz$'; then
36 cat $trace | gunzip | tcpdump -r - -w $out "$filter"
37 else
38 tcpdump -r $trace -w $out "$filter"
39 fi
40
41 echo connection in $out
42 ls -al $out