portSearch
In Case you are looking for connections
# macOS: show open ports
netstat -ap tcp | grep -i "listen"
# With Process ID:
netstat -ap tcp -v | grep -i "listen" | awk '{ print $9 , $4 }'
# macOS alternative (requires root):
sudo lsof -PiTCP -sTCP:LISTEN
# With Process Name:
netstat -ap tcp -v \
| grep -i "listen" \
| awk '{ "ps -o comm= -p " $9 | getline cmd; print cmd " \t\t " $4}'
# Fancy Version:
function lop(){
# Listen Open Ports (lop)
# Shows Process with Workdir and the Port it listens to
echo "PID\tPROG\tWORKDIR\t\t\tPORT"
netstat -ap tcp -v \
| grep -i "listen" \
| awk '{ "lsof -p " $9 " | grep cwd" | getline cmd; print cmd " " $4 }' \
| grep -E '(localhost|\*).\d+$' \
| uniq \
| awk '{ print $2, $1, $9, $NF}'
}