Use ss instead of netstat.

This commit is contained in:
Manuel Friedli 2020-08-04 18:00:22 +02:00
parent 3a15ac1ba3
commit 11c246b02c

View file

@ -468,20 +468,15 @@ banned="$(exec_as_root fail2ban-client get "${jail}" banip)"
# Determine the current connections to the desired port; store the raw data in # Determine the current connections to the desired port; store the raw data in
# $fileraw. # $fileraw.
magic=$(ss -HOn state established "( sport = :${port} )"|tr -s '[:blank:]'|cut -d' ' -f5) connections=$(ss -HOn state established "( sport = :${port} )" | tr -s '[:blank:]' | cut -d' ' -f5)
ipv6mappedipv4="$(grep '^\[::ffff:' - < "${magic}")" # IPv6-mapped-IPv4: [::ffff:192.168.0.1]:443
pureipv4="$(grep '^[^[]' - < "${magic}")" echo "${connections}" | grep '^\[::ffff:' - | cut -d: -f4 | cut -d] -f1 > "${fileraw}"
# Pure IPv4: 192.168.0.1:443
echo "MAPPED: ${ipv6mappedipv4}" echo "${connections}" | grep -v '^\[' - | cut -d: -f1 >> "${fileraw}"
echo "PURE: ${pureipv4}"
exit
netstat -nt | grep "${MY_IP}:${port}" | tr -s '[:blank:]' | cut -d' ' -f5 \
| cut -d: -f1 | sort > "${fileraw}"
# Group and sort the data into the subnet-specific files. # Group and sort the data into the subnet-specific files.
cp "${fileraw}" "${file32}" sort "${fileraw}" > "${file32}"
cut -d. -f1-3 "${fileraw}" | sort > "${file24}" cut -d. -f1-3 "${fileraw}" | sort > "${file24}"
cut -d. -f1-2 "${fileraw}" | sort > "${file16}" cut -d. -f1-2 "${fileraw}" | sort > "${file16}"
cut -d. -f1 "${fileraw}" | sort > "${file8}" cut -d. -f1 "${fileraw}" | sort > "${file8}"