标题: [网络工具] 批处理nbtstat扫描局域网IP [打印本页]
作者: neorobin 时间: 2010-8-18 23:40 标题: 批处理nbtstat扫描局域网IP
有时, nbtstat -r 不一定可以显示局域网所有的活动主机, 论坛里以前有用 start /b ping ... 来扫描的, 这里尝试换用 start /b nbtstat, 速度不见得快, 换个方式而已.
试用代码前, 请用 实际的 TAB 字符替换 ★
测试环境: WinXPSP3 CHS- @echo off & setlocal enabledelayedexpansion & color 0a & mode con lines=3
- set "TAB=★"
- for /f "tokens=2 delims= " %%i in ('mode ^| findstr "列"') do set /a cols=%%i-11
- (set /a rate=0)&(set lastPct=)
- <nul set /p=nbtstat.exe 扫描中...
- >tmp~ (
- for /f "tokens=3-6 delims=.: " %%a in ('ipconfig /all^|find /i "default gateway"') do (
- set "total=254"
- set IPDefaultGateway=%%a.%%b.%%c.%%d
- for /f %%h in ("!IPDefaultGateway!") do set IPDefaultGateway=%%h
- for /l %%v in (1,1,!total!) do (
- start /b nbtstat -A %%a.%%b.%%c.%%v
- set /a pct=%%v*100/total+1000
- if "!pct:~0,2!" equ "10" (set pct= !pct:~2!) else set "pct=!pct:~1!"
- set /a n=%%v*cols / total
- if !n! gtr !rate! (call :reflesh
- ) else if "!lastPct!" neq "!pct!" (call :reflesh
- )
- )
- )
- )
-
- cls & <nul set /p=等待扫描完成...
- :wait
- >nul 2>nul (
- wmic process where "Caption='NBTSTAT.EXE'" get /value|findstr /ic:"CommandLine"&&(title waiting... & goto :wait)||(title scaning complete.)
- )
-
- set /a cnt=1000
- >HostIPlist (
- echo 序号!TAB!IP 地址!TAB!!TAB!MAC 地址!TAB!!TAB!!TAB!主机名
- echo ===============================================================
- for /f "tokens=2" %%m in ('arp -a^|findstr /ic:"!IPDefaultGateway! "') do (
- echo !cnt:~-3!!TAB!!IPDefaultGateway!!TAB!%%m!TAB!"网关"
- )
- for /f "delims=<" %%a in ('findstr /ic:"<00> UNIQUE" tmp~') do (
- set /a cnt+=1
- set hostname=%%a
- call :truncHeadSpace hostname
- call :truncTailSpaces hostname
- for /f "tokens=2 delims=[]" %%h in ('ping -a -n 1 "!hostname!" ^| find "["') do <nul set /p=!cnt:~-3!!TAB!%%h
- for /f "tokens=4" %%m in ('nbtstat -a "!hostname!"^|findstr /ic:"MAC Address"') do echo !TAB!%%m!TAB!!hostname!
- )
- )
- start notepad HostIPlist
- echo. & echo 扫描完成. & title nbtscan 扫描完成.
- (<nul set /p=任意键退出...) & >nul pause
- del tmp~
- del HostIPlist
- exit
-
- :reflesh
- set "tt=!pct!%%"&(for /l %%j in (1,1,!rate!) do set tt=!tt!^>)&(title !tt!)
- (set /a rate=n)
- (set lastPct=!pct!)
- exit /b
-
- :truncTailSpaces rem 去掉尾部若干半角空格 调用格式: call :truncTailSpaces 字符串变量名
- if "!%1:~-1!" equ " " (set %1=!%1:~0,-1!)&(call :truncTailSpaces %1)
- exit /b
-
- :truncHeadSpace
- if "!%1:~0,1!" equ " " (set %1=!%1:~1!)&(call :truncHeadSpace %1)
- exit /b
复制代码
作者: caruko 时间: 2010-8-19 10:58
一般是用net view 显示活动主机的吧..
不过确实可能会有遗漏的。
作者: fcxk 时间: 2015-5-9 14:21
回复 1# neorobin
扫描完成、窗口等几十秒再关、是不会删除临时文件
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |