怎么在cmd查局域网所有的ip

2020-10-25 科技 77阅读
我以前刚好做过类似的批处理,我的代码的作用是搜寻指定网段的局域网中未被使用的IP地址,并把这些未被使用的IP地址保存到C:\IPList.txt文件中。如果你要找已被使用的IP地址,则只需将下面这一句中的 || 换成 && 即可。(注意,下面貌似两行,实际上是一句话,必须放在同一行里,这可是这段代码的精华所在。)
---------------------------------------------------------------------
For /L %%f in (1,1,254) Do echo %net%.%%f & Ping -n 1 %net%.%%f >test.txt & Find "from" test.txt || echo %net%.%%f >> IPList.txt
---------------------------------------------------------------------
将以下代码复制到记事本,保存文件为"搜寻未被使用的IP.cmd",然后执行这个文件即可。
完整源代码如下:
---------------------------------------------------------------------
@Echo off
title 搜寻未被使用的IP地址
c:
cd\
set /p net= 请指定您要检查的网段(IP地址前三位):
echo.
echo 正在搜寻,请稍等……
echo.
echo 要中途结束请按“Ctrl+C"
echo ======================================== > IPList.txt
echo 未被使用的IP地址清单>> IPList.txt
echo.>>iplist.txt
echo 网段:%net%.0>>IPList.txt
echo 日期:%date%>>iplist.txt
echo 时间:%time%>>iplist.txt
echo.>>iplist.txt
echo ======================================== >> IPList.txt
For /L %%f in (1,1,254) Do echo %net%.%%f & Ping -n 1 %net%.%%f >test.txt & Find "from" test.txt || echo %net%.%%f >> IPList.txt
del test.txt /f /a
cls
echo Finished!
echo ======================================== >> IPList.txt
echo Finished! >> IPList.txt
echo ======================================== >> IPList.txt
Notepad.exe "c:\IPList.txt"
---------------------------------------------------------------------
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com