]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/consort.sh
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2013 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 # sort conntrack table entries based on ip addresses
27 's/.*src=([0-9\.]+).*dst=([0-9\.]+).*src=.*/\'$1'#\0/' $FILE_NAME \
30 -k 1,1n
$SORT_ORDER -k 2,2n
$SORT_ORDER -k 3,3n
$SORT_ORDER -k 4,4n
$SORT_ORDER \
36 # sort conntrack table entries based on port addresses
41 's/.*sport=([0-9]+).*dport=([0-9]+).*src=.*/\'$1'#\0/' $FILE_NAME \
50 # sort conntrack table entries based on protocol
54 's/^[0-9a-zA-Z]+[ ]+[0-9]+[ ]+([a-zA-Z0-9]+)/\1#\0/' $FILE_NAME \
63 # sort conntrack table entries based on connection status
67 's/^[0-9a-zA-Z]+[ ]+[0-9]+[ ]+[a-zA-Z0-9]+[ ]+[0-9]+[ ]+[0-9]+[ ]+([a-zA-Z_0-9]+)[ ]+|^[0-9a-zA-Z]+[ ]+[0-9]+[ ]+[a-zA-Z0-9]+[ ]+[0-9]+[ ]+[0-9]+([ ]+)/\1#\0/' $FILE_NAME \
76 # sort conntrack table entries based on connection time to life
80 's/^[0-9a-zA-Z]+[ ]+[0-9]+[ ]+[a-zA-Z0-9]+[ ]+[0-9]+[ ]+([0-9]+)[ ]+/\1#\0/' $FILE_NAME \
89 # sort conntrack table entries based on downloaded bytes
90 do_downloaded_bytes_sort
() {
93 's/.*src=.*bytes=([0-9]+).*src=/\1#\0/' $FILE_NAME \
102 # sort conntrack table entries based on uploaded bytes
103 do_uploaded_bytes_sort
() {
106 's/.*src=.*bytes=([0-9]+).*/\1#\0/' $FILE_NAME \
118 if [ $# -lt 2 ]; then
119 echo "Usage: consort <sort criteria 1=srcIp,2=dstIp,3=srcPort,4=dstPort,5=protocol,6=connection status> <a=ascending,d=descending> [input file]"
120 echo " consort.sh 1 a a.txt"
121 echo " cat a.txt | consort 1 d"
125 if [[ 'a d A D' =~
$2 ]]; then
126 if [[ 'd D' =~
$2 ]]; then
130 echo "Unknown sort order \"$2\""
136 echo "File not found."
142 if [[ '1 2' =~
$1 ]]; then
144 elif [[ '3 4' =~
$1 ]]; then
145 do_port_sort $
(($1-2))
146 elif [[ '5' =~
$1 ]]; then
148 elif [[ '6' =~
$1 ]]; then
150 elif [[ '7' =~
$1 ]]; then
152 elif [[ '8' =~
$1 ]]; then
153 do_downloaded_bytes_sort
154 elif [[ '9' =~
$1 ]]; then
155 do_uploaded_bytes_sort
157 echo "Unknown sort criteria \"$1\""