Using lsof or netstat to view all IPs connected to my host
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 Code:
netstat -lantp | grep ESTABLISHED | awk '{print $7" "$4" "$5}' | sort -u My questions are as follows:
Example output: Code:
<process_name> <local_port> <remote_ip>:<remote_port> 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> 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 The Desired//Wanted output: Code:
<process_name> <local_port> <remote_ip>:<remote_port> |
Try this and tell me if it does what you are expected
Code:
netstat -lantp | grep ESTABLISHED | awk '{print $7, $4, $5}' | sort -u |sed 's/[0-9]*\///g' sshd: 10.0.1.1:22 192.6.2.99:63187 |
or here it is a longer version but which does what you want:
Code:
netstat -lantp | grep ESTABLISHED | awk '{print $7, $4, $5}' | sort -u |sed -e 's/[0-9]*\/\(.*\):\s[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}:\([0-9]\{1,5\}\)/\1 \2/g' sshd 22 192.6.2.99:63187 Best regards, Angel. |
Shame on me. I have neglected this thread for almost a year.
Code:
netstat -lantp | grep ESTABLISHED | awk '{print $7, $4, $5}' | sort -u |sed 's/[0-9]*\///g' Code:
netstat -lantp | grep ESTABLISHED | awk '{print $7, $4, $5}' | sort -u |sed -e 's/[0-9]*\/\(.*\):\s[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}:\([0-9]\{1,5\}\)/\1 \2/g' It should be mocp 54168 178.159.0.11:7506 |
All times are GMT -5. The time now is 11:13 AM. |