-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetstat.sh
60 lines (59 loc) · 1.56 KB
/
netstat.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
start="unok"
t=1 #set time
i=0
title=()
value=()
j=0
while :
do
netstat -s -n |
while read line
do
if [ "${line}" == "udp:" ]||[ "${line}" == "Udp:" ]||[ "${line}" == "UDP:" ];then
start="ok"
j=0
i=0
echo "udp:"
continue
fi
if [ "${start}" == "ok" ];then
result=$(echo $line | grep ":")
if [[ "$result" != "" ]];then
#echo $i
start="unok"
let j++
while [ $i -lt $j ]
do
lenT=${#title[$i]}
lenV=${#value[$i]}
if [ $lenT -lt $lenV ];then
while [ $lenT -lt $lenV ]
do
title[$i]="_${title[$i]}"
let lenT++
done
else
while [ $lenV -lt $lenT ]
do
value[$i]="_"${value[$i]}
let lenV++
done
fi
tilstr="$tilstr|${title[$i]}"
valstr="$valstr|${value[$i]}"
let i++
done
echo $tilstr
echo $valstr
break
else
title[j]=${line#* }
value[j]=${line%% *}
let j++
#echo " $line"
fi
fi
done
sleep $t
done