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
Post a Comment