1

Using netstat -aon | findstr /I "1234", I can monitor that this port is open, but there is an issue: this is what the result looks like:

UDP    0.0.0.0:1234    *:*     5064
UDP    0.0.0.0:1234    *:*     5064
UDP    0.0.0.0:1234    *:*     5064
UDP    0.0.0.0:1234    *:*     5064

So, whenever my program (with Progress ID 5064) fails opening that port, I have no idea when this actually happens.

So, I would like something like:

while true:
  netstat -aon | findstr /I "1234"
  time /T
end

(I already checked netstat /?, but I don't find any switch which shows the timestamp.)

Does anybody have an idea?

(I'm working on Windows Server 2019.)

1 Answer 1

1

Well, in PowerShell, you can literally do what's in your example using a while loop:

while ($true) {
    Get-Date
    netstat -asdfgh
    Start-Sleep 1
}

...that being said, I believe that's the entirely wrong approach. Socket listen failure is detectable – the respective functions will return an error – so if your program fails to listen on its configured port, on a server, it should generate its own log messages indicating that it has a problem.

Those log messages would then include the time and date when the message was output. (If you can send messages to Windows Event Log – or to a Syslog collector – it would usually include the time/date automatically.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .