Skip to content

Instantly share code, notes, and snippets.

@Aurora12
Last active December 1, 2021 12:33
Show Gist options
  • Save Aurora12/890d592a8ccfcca517512c12b6c7ffe5 to your computer and use it in GitHub Desktop.
Save Aurora12/890d592a8ccfcca517512c12b6c7ffe5 to your computer and use it in GitHub Desktop.
Bash commands to show open TCP listening ports
# Debian
# Without sudo won't show pids and process names
sudo netstat -tlpn|grep LISTEN

# macOS
# Increase +c for better names visibility
# Without sudo only shows processes of the current user
sudo lsof -i -nP +c 30|grep LISTEN
@EdThePro101
Copy link

EdThePro101 commented Jan 6, 2021

This works on Windows as well. You'll just need to modify the netstat command a bit, and for grep, you need to have MinGW, Cygwin or Git Bash* installed. This command can also be called without administrative requirements in cmd.exe.

netstat -a | grep LISTENING

* - When using Git Bash or Cygwin, I find it best to call grep in the respective terminals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment