hoyong

导航

windows CMD命令查看局域网内所有主机名及IP

COLOR 0A
CLS
@ECHOOff
Title查询局域网内在线电脑IP
:send
@ECHO off&setlocal enabledelayedexpansion
ECHO 正在获取本机的IP地址,请稍等...
for/f "tokens=3 skip=2 delims=: "%%i in('nbtstat -n')do(
set"IP=%%i"
set IP=!IP:~1,-1!
ECHO 本机IP为:!IP!
goto:next
)
:next
for/f "delims=. tokens=1,2,3,4"%%i in("%IP%")doset range=%%i.%%j.%%k
ECHO.&ECHO 正在获取本网段内的其它在线计算机名,请稍等...
ECHO 本网段【%range%.*】内的计算机有:
for/f "delims="%%i in('net view')do(
set"var=%%i"
::查询在线计算机名称
if"!var:~0,2!"=="\\"(
set"var=!var:~2!"
ECHO !var!
ping -n 1!var!>nul
))
ECHO.
ECHO 正在获取本网段内的其它在线计算机IP,请稍等...
for/f "skip=3 tokens=1,* delims= "%%i in('arp -a')do ECHO IP:%%i 正在使用
ECHO.
ECHO 查询完毕,按任意键退出...
pause>nul
//该代码片段来自于: http://www.sharejs.com/codes/shell/5917

 

Example1:

1 for /L %i IN (1,1,254) DO ping -w 2 -n 1 192.168.0.%i
2 
3 arp -a

 

 

Example2:  ( For JiangBei TuShu)

 1 for /L %i IN (1,1,254) DO ping -w 2 -n 1 172.16.104.%i
 2 for /L %i IN (1,1,254) DO ping -w 2 -n 1 172.16.105.%i
 3 for /L %i IN (1,1,254) DO ping -w 2 -n 1 172.16.106.%i
 4 for /L %i IN (1,1,254) DO ping -w 2 -n 1 172.16.107.%i
 5 for /L %i IN (1,1,254) DO ping -w 2 -n 1 172.16.108.%i
 6 for /L %i IN (1,1,254) DO ping -w 2 -n 1 172.16.109.%i
 7 for /L %i IN (1,1,254) DO ping -w 2 -n 1 172.16.110.%i
 8 for /L %i IN (1,1,254) DO ping -w 2 -n 1 172.16.111.%i
 9 
10 
11 arp -a

 

posted on 2019-03-15 11:05  hoyong  阅读(6702)  评论(0编辑  收藏  举报