Optimized fetching port-program logic
This commit is contained in:
29
ufw.awk
29
ufw.awk
@@ -13,25 +13,30 @@
|
|||||||
# Give options to process only a certain number of day's log
|
# Give options to process only a certain number of day's log
|
||||||
|
|
||||||
declare port_programs=$(ss -lpntu |
|
declare port_programs=$(ss -lpntu |
|
||||||
awk 'BEGIN {FS=":"} NR>1&&$1!~"\\["{print $2, $4} NR>1&&$1~"\\["{print $4, $8}' |
|
awk 'BEGIN {FS=":"}
|
||||||
|
NR>1 && $1 !~ "\\[" {print $2, $NF} # Row does NOT contains [ -> Fetch 2nd and last columns
|
||||||
|
NR>1 && $1 ~ "\\[" {print $4, $NF} # Row contains [ -> Fetch 4th and last columns
|
||||||
|
' |
|
||||||
awk '{
|
awk '{
|
||||||
print $1,
|
port = $1
|
||||||
substr($3,
|
program = substr($3,
|
||||||
index($3, "\"")+1,
|
index($3, "\"")+1,
|
||||||
index($3, ",")-index($3,"\"")-2) | "sort -u"}' |
|
index($3, ",")-index($3,"\"")-2)
|
||||||
awk '{
|
|
||||||
if (port_programs[$1]==""){
|
# Add multiple programs listening on a single port as comma separated list
|
||||||
port_programs[$1]=$2
|
if (port_programs[port]==""){
|
||||||
}else{
|
port_programs[port]=program
|
||||||
port_programs[$1]=port_programs[$1]","$2
|
}else if (index(port_programs[port], program) > 0){ # Remove duplicates
|
||||||
|
next
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
port_programs[port]=port_programs[port]","program
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END {
|
END {
|
||||||
for (port in port_programs)
|
for (port in port_programs)
|
||||||
print port, port_programs[port]
|
print port, port_programs[port]
|
||||||
}'
|
}')
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
LC_ALL=C cat /var/log/ufw.log | mawk '
|
LC_ALL=C cat /var/log/ufw.log | mawk '
|
||||||
function GetValue(currentColumnValue, stringToSearch) {
|
function GetValue(currentColumnValue, stringToSearch) {
|
||||||
|
|||||||
Reference in New Issue
Block a user