Command line for looking at specific port

前端 未结 13 1203
孤街浪徒
孤街浪徒 2020-12-02 03:40

Is there a way to examine the status of a specific port from the Windows command line? I know I can use netstat to examine all ports but netstat is slow and looking at a spe

13条回答
  •  自闭症患者
    2020-12-02 04:18

    To improve upon @EndUzr's response:

    To find a foreign port (IPv4 or IPv6) you can use:

    netstat -an | findstr /r /c:":N [^:]*$"
    

    To find a local port (IPv4 or IPv6) you can use:

    netstat -an | findstr /r /c:":N *[^ ]*:[^ ]* "
    

    Where N is the port number you are interested in. The "/r" switch tells it to process it as regexp. The "/c" switch allows findstr to include spaces within search strings instead of treating a space as a search string delimiter. This added space prevents longer ports being mistreated - for example, ":80" vs ":8080" and other port munging issues.

    To list remote connections to the local RDP server, for example:

    netstat -an | findstr /r /c:":3389 *[^ ]*:[^ ]*"
    

    Or to see who is touching your DNS:

    netstat -an | findstr /r /c:":53 *[^ ]*:[^ ]*"
    

    If you want to exclude local-only ports you can use a series of exceptions with "/v" and escape characters with a backslash:

    netstat -an | findstr /v "0.0.0.0 127.0.0.1 \[::\] \[::1\] \*\:\*" | findstr /r /c:":80 *[^ ]*:[^ ]*"
    

提交回复
热议问题