0

How can I format netstat output so I have a list of TCP connections made to the server?

A bit like this:

192.168.234.1 51780
192.168.234.221 51444
192.168.234.251 51447

The closest I got was six columns with all the values from the netstat, but I just need the origin IP of the established connections using netstat -na -t | grep ESTABELECIDO

  • To what server? Incoming connections? – Jesse_b May 11 '18 at 19:44
  • is netstat -p tcp -n | awk '$NF ~ "ESTABELECIDO"{print $5}' sort of what you are looking for? – Jesse_b May 11 '18 at 19:47
  • I updated the post, sorry for that @jesse_b – Bruno Aioria May 11 '18 at 19:48
2

For the formatted output , you can use awk and tr

netstat -na -t | awk '/ESTABELECIDO/{print $4}' | tr ':' ' '

As, you asked origin IP and origin IP will be from our machine only, so I mentioned field $4 in awk, otherwise use $5 in awk for other machine IP address.

  • @Jesse_b Yes you are right, i have edited my answer to reflect your suggestion – Arushix May 16 '18 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.