我有一个端口扫描工具,它使用命令行程序称为paping.exe,(如果你想要它你可以在这里安装它,https://code.google.com/archive/p/paping/downloads)到目前为止我可以让它扫描几个端口一个IP或网站,但是手动扫描1-65,535的所有端口是非常耗时的,所以我需要它扫描所有65,535个端口并显示哪些端口是打开的而不需要花费很多时间
继承我的代码:
@echo off
::BatchGotAdmin
::-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe"
"%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"="
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >>
"%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
::--------------------------------------
:PortScan
set /p Ip=Enter a IP or Website to ping:
paping.exe %Ip% -p 1 -c 1
paping.exe %ip% -p %port% -c 1 | findstr "protocol=TCP"
if %errorlevel% == 0 (
cls
color 0a
echo Port %port% is Open.
) else (
cls
color 4
echo Port is Closed.
)
pause
goto :LoopScan
:LoopScan
@echo off
setlocal enableextensions enabledelayedexpansion
set /a count = 1
set /a count += 1
paping.exe %ip% -p !count! -c 1 | findstr "protocol=TCP"
if %errorlevel% == 0 (
cls
color 0a
set /
goto openport
echo These ports are open: %%n
) else (
cls
color 4
goto closeport
echo Ports are Closed.
)
pause
)
endlocal
pause
openport:
Echo The Following Ports Are Open: !count!