Created
May 10, 2024 16:56
-
-
Save mohd-akram/ecf9b752e155c06d142312bbcad5f49d to your computer and use it in GitHub Desktop.
List open TCP and UDP ports
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
#!/bin/sh | |
# usage: lstcp [options] [port] | |
lstcp() ( | |
while getopts : o; do opts="$opts -$OPTARG"; done; shift $((OPTIND-1)) | |
lsof -i tcp"${1+:}$1" -s tcp:listen $opts | |
) | |
# usage: lsudp [options] [port] | |
lsudp() ( | |
while getopts : o; do opts="$opts -$OPTARG"; done; shift $((OPTIND-1)) | |
lsof -i udp"${1+:}$1" $opts | grep -vF -e '*:*' -e '->' | |
) | |
# usage: lsport [options] [port] | |
lsport() ( | |
while getopts : o; do opts="$opts -$OPTARG"; done; shift $((OPTIND-1)) | |
lsof -i"${1+:}$1" -s tcp:listen $opts | grep -vF -e '*:*' -e '->' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment