1

Hi I need to find out how to show on 1 line of text in a file

TCP | Local IP | Remote IP | ESTABLISHED | ELAPSED TIME

i can manage to do it all apart from getting the elapsed time with the following bat file

@ECHO OFF
SET _file=%~n1%
SET _pathname=%~f1%
SET _ext=%~x1%

FOR /f "tokens=6-8 delims=/ " %%G IN ('NET TIME \\%computername%') DO (
     SET _mm=%%G
     SET _dd=%%H
     SET _yy=%%I
 )

FOR /f "tokens=1,2 delims=: " %%G IN ('time/t') DO (
     SET _hr=%%G
     SET _min=%%H
)

NETSTAT -n | find "3389"| find "ESTABLISHED"> C:\conn\%computername%.csv
EXIT

Can anyone help me please

1 Answers1

0

netstat -n has no timestamp, so where should elapsed time stem from?
For the output the pipe symbol has to be escaped with a caret ^|

(
  For /f "tokens=1-4" %%A in (
    'NETSTAT -n ^| find "3389"^| find "ESTABLISHED"'
  Do Echo %%A^|%%B^|%%C^|%%D^|whatsoever
) >C:\conn\%computername%.csv