- @echo off & setlocal enabledelayedexpansion & title 局域网扫描
- set /p net=输入网段(默认192.168.1):
- if "%net%"=="" set net=192.168.1
- set /p start=输入起始IP地址(默认起始地址为1):
- if "%start%"=="" set start=1
- set /p end=输入终止IP地址(默认终止地址为254):
- if "%end%"=="" set end=254
- set "txt=局域网在线IP扫描结果.txt"
- set n=0
- set m=0
- >>%txt% echo 扫描地址:%net%.%start% - %net%.%end%
- echo.在线IP MAC地址 计算机名
- for /l %%a in (%start% 1 %end%) do (
- set /p a="%net%.%%a"<nul
- ping %net%.%%a -n 1 -w 50 >nul
- if errorlevel 1 (
- cd.
- ) else (
- for /l %%i in (1,1,15) do (set /p=<nul)
- set /p=%net%.%%a <nul
- for /f "tokens=1*" %%b in ('nbtstat -a %net%.%%a^|findstr "<00>.*唯一 MAC <00>.*UNIQUE"') do (
- if "%%b"=="MAC" (
- for /f "tokens=2 delims== " %%d in ("%%c") do (
- <nul set /p=%%d
- <nul set /p=!pcn!
- >>%txt% echo %net%.%%a %%d !pcn!
- set /a n+=1
- )
- ) else (
- set pcn=%%b
- if "!pcn:~-4!"=="<00>" set pcn=!pcn:~0,-4!
- )
- set q=1
- )
- if "!q!" neq "1" for /f "tokens=2" %%b in ('arp -a %net%.%%a^|findstr "%net%.%%a.*-[a-f0-6]"') do <nul set /p=%%b &<nul set /p=-&set /a m+=1
- echo.
- set q=
- set /p="192.168.1.%%a"<nul
- )
- for /l %%i in (1,1,15) do (set /p=<nul)
- )
- >>%txt% echo 扫描结果:%n%台在线计算机 %m%台其它设备 (%date% %time:~0,8%)
- (for /l %%a in (1 1 60) do <nul set /p=-)>>%txt%
- echo,>>%txt%
- set /p=扫描完成,发现%n%台在线计算机。<nul
- if "%m%" neq "0" set /p=%m%台其它设备。<nul
-
- echo.
- echo.结果保存在“%txt%”
- pause
- start "" %txt%
复制代码
|