Asis
Asis

Reputation: 65

Get Ports grep using netstat -v

I want to get a list of ports of the established connections using netstat -v grep.

I am trying this:

sudo netstat -v | grep "ESTABLISHED" | cut -d: -f5

Any help?

Upvotes: 0

Views: 282

Answers (2)

Cyrus
Cyrus

Reputation: 88969

Try this with $5 and $4:

netstat -v | awk '/ESTABLISHED/ {split($5, array, ":"); print array[2]}'

Upvotes: 2

Anil Pediredla
Anil Pediredla

Reputation: 744

Please try

netstat -v| grep "ESTABLISHED"| awk '{print $5}' | cut -d ":" -f2

Upvotes: 1

Related Questions