PC,노트북,컴퓨터

ping 테스트로 응답하는 IP찾는 도스 배치파일

바람사탕 2024. 5. 30. 23:53
반응형

ping_results.txt

172.16.1.1 OK 
172.16.1.14 OK 
172.16.1.24 OK 
172.16.1.145 OK 
...

ping_sweep.bat
0.00MB

@echo off
setlocal enabledelayedexpansion

echo 1부터 254까지의 숫자를 루프하여 각 IP 주소를 ping 명령으로 테스트합니다.
echo ping 명령이 성공적으로 응답을 받으면, 해당 IP 주소를 출력합니다.

ipconfig

rem Define the subnet (change this to match your network)
set subnet=172.16.1.


rem Define the output file
set output_file=ping_results.txt

rem Clear the output file if it exists
if exist %output_file% del %output_file%

rem Loop through all possible host addresses in the subnet
for /L %%i in (1,1,255) do (
    rem Ping each address with a timeout of 50ms
    echo %subnet%%%i
    ping -n 1 -w 50 %subnet%%%i > nul
    if !errorlevel! == 0 (
        echo %subnet%%%i OK >> %output_file%
        echo %subnet%%%i OK
    )
    rem Check the exit code of the ping command
    rem echo errorlevel=%errorlevel%
)

rem Open the output file when done
start notepad %output_file%

endlocal
반응형