I am trying to get the result of a netstat -na | grep specific_ip, run remotely via a batch script calling plink.exe to be formatted into a set of ip/port pairs as:
Code:
IP- client_ip_1
Port- client_port_1
IP- client_ip_2
Port- client_port_2
netstat -na outputs like so, IPs have been changed:
Code:
tcp 0 0 ::ffff:server_ip:22 ::ffff:client_ip_1:client_port_1 ESTABLISHED
tcp 0 52 ::ffff:server_ip:22 ::ffff:client_ip_2:client_port_2 ESTABLISHED
The problem I have is that when I use the command:
Code:
"C:\Program Files\PuTTY\plink.exe" "-l" "user" "-pw" "pass" server_ip "netstat -na | grep 172.16 | awk -F: '{print \"IP-\t\"$8\"\nPort-\t\"$9}'"
My output shows:
Code:
IP- client_ip_1
Port- client_port_1 ESTABLISHED
IP- client_ip_2
Port- client_port_2 ESTABLISHED
I want to remove the word ESTABLISHED, but since I am running this via plink I would like to do it in one command. I tried to use awk within awk to accomplish this:
Code:
"C:\Program Files\PuTTY\plink.exe" "-l" "user" "-pw" "pass" server_ip "netstat -na | grep 172.16 | awk -F: '{print \"IP-\t\"$8\"\nPort-\t\"; print awk '{print $1}' $9}'"
But I got an error as seen in the attached jpg.
Any solutions/suggestions are welcome.