2017年11月10日 星期五

批次ping主機的方式

最近陸續增加後,總計家裡有4台Pi機器
有些Pi是否關機了,卻沒注意到
所以想要利用排程來執行ping
並且把機器狀態存成檔案後寄出

我們用一行指令,就可以達成
首先,建立批次檔 Pi.bat
再裡面輸入下列指令

============================
@Echo off
del act.txt
del na.txt
echo ==========正常連線的設備========== >> act.txt
echo ==========斷線========== >> na.txt
@for /l %%i in (100,1,108) do @ping -n 1 -w 40 192.168.1.%%i& if errorlevel 1 (echo 192.168.1.%%i>>na.txt) else (echo 192.168.1.%%i>>act.txt)
cls
Echo 完成!!
@echo on
notepad act.txt & notepad na.txt


如果再 MS-DOS模式下,輸入下列指令
============================
@for /l %i in (100,1,108) do @ping -n 1 -w 40 192.168.1.%i& if errorlevel 1 (echo 192.168.1.%i>>na.txt) else (echo 192.168.1.%i>>act.txt)

指令相差只是 %%i 跟 %i 的差別,再批次檔要用 %%i

=============================

指令解釋如下:
@for /l %%i in (100,1,108) ==> 從 192.168.1.100 ping 到 192.168.1.108 每次ip後碼+1

 do @ping -n 1 -w 40 192.168.1.%%i ==> 指定ip範圍

& if errorlevel 1 (echo 192.168.1.%%i>>na.txt)  ==> 如果是錯誤的,把ip位置輸入到 na.txt

else (echo 192.168.1.%i>>act.txt)     ===> 如果是正常的,把ip位置輸入到 act.txt

沒有留言:

張貼留言

BaoFeng DM-32

DM-32 Info CPS DMR Radio Setup v1.28 EN 確認能用 寫頻線使用內含晶片的 USB-SERIAL CH340  ------------------ Software Used: DM32 CPS Version : V.1.28 Device...