0

I am trying to determine what command I can use to check if a port is in use in Windows. I looked into Command line for looking at specific port but none of the answer fits exactly what I am looking for.

For example I want to look whether port 500 is in use, I would use netstat –an | findstr /r :500 but the results would appear to be

 TCP    0.0.0.0:5000           0.0.0.0:0              LISTENING
 TCP    [::]:5000              [::]:0                 LISTENING
 UDP    0.0.0.0:500            *:*
 UDP    127.0.0.1:50027        *:*
 UDP    [::]:500               *:*

That's not exactly what I want. I tried netstat -an | findstr /r :500[\s]+ then nothing would show. Not sure how I can fix the query.

Any ideas?

Community
  • 1
  • 1
user1763590
  • 117
  • 2
  • 14

1 Answers1

0

FindStr command does not sport a full PCRE engine. So while the regular expression assertion [^0-9:] excludes numbers and a colon; the \s assertion simply escapes the letter s which will then match just the letter s. Whereas in PCRE \s represents whitespace.

See also this findstr documentation where it states \x matches a meta character but the document does not go into details about the other PCRE character classes like \s, \w, \d etc.

Try it for you self. From the your c:\windows\system32 folder, issue the follow command

dir | findstr \r "\s\s" | more

You should receive a list of files which only have a double s like sysclass.dll, or ssdpapi.dll... etc.

Ro Yo Mi
  • 14,790
  • 5
  • 35
  • 43