简体   繁体   English

Windows打开端口命令行

[英]Windows open ports command line

Is there any way to see open ports of windows in a specific range using command line? 有什么方法可以使用命令行查看特定范围内的Windows打开端口吗?

For example i want to see open ports in range 1-1024. 例如,我想查看范围1-1024中的开放端口。

This will list all open (in use) ports. 这将列出所有打开(使用中)的端口。

netstat -na

Filtering is a bit harder. 过滤有点困难。 This script takes two ports as the (inclusive) range of local ports to filter for. 该脚本将两个端口作为要过滤的本地端口(包括)范围。

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

SET STARTPORT=%1
SET ENDPORT=%2

FOR /F "delims=|" %%l IN ('netstat -na') DO (
    FOR /F "tokens=2" %%a IN ("%%l") DO (
        REM IPv6 uses colons, too.
    SET "LOCAL=%%~a"
    SET "LOCAL=!LOCAL:*]=0!"
        FOR /F "delims=: tokens=2" %%p IN ("!LOCAL!") DO (
            IF %%p LEQ %ENDPORT% ( IF %%p GEQ %STARTPORT% ( @ECHO %%l ) )
        )
    )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM