linux - How to print the IP and the Port separately with netstat? -


i want print ip , port separately using netstat command,

i tried this:

netstat -nat | awk '{print $4}' 

but gives me that:

192.168.1.213:40405 

i want that:

first ip: 192.168.1.213

and command port: 40405

if want them different commands, use sed like:

netstat -nat | awk '{print $4}' | sed -e 's/:.*//' # gives ip netstat -nat | awk '{print $4}' | sed -e 's/.*://' # gives port 

depending on how you're using it, store in bash variable , accomplish same thing while access like

both=$(netstat -nat | awk '{print $4}') ip=${both%%:*} port=${both##*:} 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -