Created
May 20, 2016 08:59
-
-
Save dietercastel/016e90ef21bc2328c4446c03d4b072a1 to your computer and use it in GitHub Desktop.
Finds pids that are listening to ports (atm tcp6 on all interfaces only). Ideas for extension include: udp/tcp/udp6, support different interfaces, generate improved output (nice grep-able overview), ...
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
#Finds pids that are listening to ports (atm tcp6 on all interfaces only) | |
netstat | grep LISTEN | grep tcp6 | awk '{print $4 }' | awk -F':' '{print $4}' > /tmp/ports.txt | |
#convert ports to hex | |
cat /tmp/ports.txt | while read myline; do printf '%x\\n' $myline ; done > /tmp/hexports.txt | |
#get inodes from hex ports | |
grep -i -f /tmp/hexports.txt /proc/net/tcp6 | awk '{print $10}' > /tmp/inodes.txt | |
#get pids tied to inodes | |
lsof | grep -f /tmp/inodes.txt | awk '{print $2}' > /tmp/pids.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment