Last active
August 1, 2024 14:01
-
-
Save gocs/269459db9076178e08ce8a5e4434e49a to your computer and use it in GitHub Desktop.
get all pid with tcp port filtered by ipv4, command, user, and listening tcp connections
This file contains 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 | |
# show pid and port from matcher | |
MATCHER=$1 | |
if [ -n "$MATCHER" ]; then | |
sudo lsof -aPn -i4 -cnode -u${USER} -sTCP:LISTEN | grep $MATCHER | awk '{print $2 "|" $9}'; | |
exit 0; | |
fi; | |
# show all ssh tunnel tcp connections | |
sudo lsof -aPn -i4 -cnode -u${USER} -sTCP:LISTEN | tail -n +2 | awk '{print $2 "|" $9}'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment