Created
February 9, 2021 15:47
-
-
Save Saruspete/ca511162a235c7e87264e48f9ad49768 to your computer and use it in GitHub Desktop.
Check that no process is listening on ephemeral port range
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Get min/max port range from sysctl | |
prange="$(sysctl net.ipv4.ip_local_port_range| awk '{print $3,$4}')" | |
pmin="${prange% *}" | |
pmax="${prange#* }" | |
# TODO: ignore ports in sysctl net.ipv4.ip_local_reserved_ports | |
ss --listen --numeric --tcp --process | awk -v pmin=$pmin -v pmax=$pmax ' | |
$1=="LISTEN"{ | |
split($4,a,":") | |
port=a[length(a)] | |
if (port >= pmin && port <= pmax) { | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment