|
这让我想起了一段陈旧的脚本:
@echo off &color 0a &setlocal enabledelayedexpansion
call :打印网关IP
rem set "IP_S=192.168.1.1"
set /p "IP_S=请输入IP网段(默认:!IP_S!):"
set "网段IP="
for /f "tokens=1,2,3 delims=." %%a in ("!IP_S!") do (
set "网段IP=%%a.%%b.%%c."
if "" EQU "%%a" set "网段IP="
if "" EQU "%%b" set "网段IP="
if "" EQU "%%c" set "网段IP="
goto :判断网段
)
:判断网段
if "" EQU "!网段IP!" (
echo 没有找到正确的网段,任意键结束.....
pause>nul
goto :eof
)
set "网段文件=网段!网段IP:.=_!的主机.txt"
echo 网段!网段IP!的主机信息 >!网段文件!
for /l %%a in ( 1 1 255 ) do (
ping -n 2 -w 60 !网段IP!%%a | find /i "ttl" >nul && for /f "delims=" %%i in ('arp -a') do echo %%i | find /i "!网段IP!%%a " >nul && (
set "IP_S=%%i"
if " " EQU "!IP_S:~0,1!" (
echo 找到主机 %%i
echo %%i >>!网段文件!
)
)
)
start !网段文件!
echo 扫描完毕!任意键结束....
pause>nul
goto :eof
:打印网关IP
set "临时变量1="
set "临时变量2="
set "临时变量3="
echo 当前可选网关IP:
for /f "delims=" %%a in ('arp -a') do (
set "临时变量1=!临时变量2!"
set "临时变量2=!临时变量3!"
set "临时变量3=%%a"
( echo !临时变量1! | find "---" >nul) && for /f "tokens=1 delims= " %%b in ("%%a") do set "IP_S=%%b" & echo %%b
) |
|