I have found a
command that finds all established connections to my host through TCP connection.
I found the following command as useful:
Code:
netstat -lantp | grep ESTABLISHED | awk '{print $4" "$5" "$7}' | sort -u
Better (application name at the beginning):
Code:
netstat -lantp | grep ESTABLISHED | awk '{print $7" "$4" "$5}' | sort -u
My questions are as follows:
- How do I stripping the number of the process with the command netstat? (displaying only the process name)
- How can I limit the length of the process name to 5 or 8 letters?
- How do I strip the local IP address? (i.e. 192.168.1.1)
Example output:
Code:
<process_name> <local_port> <remote_ip>:<remote_port>
The current output of netstat is:
Code:
netstat -lantp | grep ESTABLISHED | awk '{print $7, $4, $5}' | sort -u
Code:
2784/transmission-g 192.168.1.1:<local_port> <remote_ip>:<remote_port>
2965/cmus 192.168.1.1:<local_port> 206.217.216.84:80
The current output of lsof is:
Code:
lsof -i -n -P | grep ESTABLISHED |awk '{print $1, $9}' | sort -u
Code:
cmus 192.168.1.1:<local_port>->206.217.216.84:80
transmiss 192.168.1.1:<local_port>-><remote_ip>:<remote_port>
The Desired//Wanted output:
Code:
<process_name> <local_port> <remote_ip>:<remote_port>