|
|
发表于 2012-5-11 10:55:08
|
显示全部楼层
本帖最后由 neorobin 于 2012-5-11 11:10 编辑
回复 1# gobi918
楼主试下下面的, 第 3 行中的 TAB 字符 (ASCII 9) 可能被论坛处理成了若干空格, 可以自己编辑并还原, 但仅影响输出的格式.- @echo off & setlocal enabledelayedexpansion & color 0a & mode con lines=2
- :remself 用 ping.exe 和 arp 来扫描和显示局域网活动 IP.
- set "TAB= "
- set /a sendCnt=2
- set /p sendCnt=Please input the number of echo requests to send(default=!sendCnt!^):
- for /f "tokens=2 delims= " %%i in ('mode ^| findstr "列"') do set /a cols=%%i-11
- (set /a rate=0)&(set lastPct=)
- arp -d
- for /f "tokens=3-6 delims=.: " %%a in ('ipconfig /all^|find /i "default gateway"') do (
- if "%%b" neq "" (
- set "total=254"
- for /f %%h in ("%%a.%%b.%%c.%%d") do set "IPDefaultGateway=%%h"
- for /l %%v in (1,1,!total!) do (
- start /b ping -n !sendCnt! %%a.%%b.%%c.%%v>nul
- echo Pinging %%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)
- )
- )
- )
- echo. & title waiting...
- :wait
- 2>nul (
- wmic process where "Caption='ping.exe'" get Caption|find /i /c "ping.EXE" && goto :wait
- )
- title PingScan 扫描完成.
- set /a cnt=1000
- >IPList (
- 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!"网关"
- )
- set /a cnt+=1
- for /f "tokens=2 delims=[]" %%t in ('ping -n 1 %computername% ^| find "["') do (
- for /f "tokens=4" %%m in ('nbtstat -a "!computername!"^|findstr /ic:"MAC Address"') do (
- for /f "delims=" %%M in ("%%m") do echo !cnt:~-3!★!TAB!%%t!TAB!%%M!TAB!!computername!
- )
- )
- for /f "tokens=1-2" %%a in ('arp -a^|findstr /ic:"dynamic"') do (
- if not "%%a"=="!IPDefaultGateway!" (
- for /f "delims=<" %%H in ('nbtstat -A %%a^|findstr /ic:"<00> UNIQUE"') do (
- set /a cnt+=1
- set hostname=%%H
- call :trim hostname
- echo !cnt:~-3!!TAB!%%a!TAB!%%b!TAB!!hostname!
- )
- )
- )
- )
- start notepad IPList
- echo. & (<nul set /p=PingScan 扫描完成. 任意键退出...) & >nul pause
- del IPList
- exit /b
- :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
- :trim strVar
- if "!%1:~-1!" equ " " set "%1=!%1:~0,-1!" & call :trim %1
- if "!%1:~0,1!" equ " " set "%1=!%1:~1!" & call :trim %1
- exit /b
复制代码 |
评分
-
查看全部评分
|