1
我是批處理新手,需要一些關於如何使腳本更短的指導... 它工作正常,但很多重複的行。消除冗餘批處理腳本
腳本發送'arp -a'到臨時文件進行解析,然後通過6個IP地址檢查它們是否是靜態的。
任何建議創建更短的更好的方法將不勝感激。謝謝 !
@ECHO OFF
cls
ECHO ---------------Check SiteC IP = Static -----------------
ARP -a > O:\temp_log.txt
SET /A var1 = 0
SET /A var2 = 0
SET /A var3 = 0
SET /A var4 = 0
SET /A var5 = 0
SET /A var6 = 0
FOR /F "tokens=1,3 delims= " %%A IN ('findstr "static" "O:\temp_log.txt"') DO IF "%% A"=="192.168.0.11" ECHO %%A = %%B && SET /A var1 = 1
IF %var1% == 1 (ECHO Match) ELSE (ECHO SiteC1 FAIL)
ECHO --
FOR /F "tokens=1,3 delims= " %%A IN ('findstr "static" "O:\temp_log.txt"') DO IF "%%A"=="192.168.0.12" ECHO %%A = %%B && SET /A var2 = 1
IF %var2% == 1 (ECHO Match) ELSE (ECHO SiteC2 FAIL)
ECHO --
FOR /F "tokens=1,3 delims= " %%A IN ('findstr "static" "O:\temp_log.txt"') DO IF "%%A"=="192.168.0.13" ECHO %%A = %%B && SET /A var3 = 1
IF %var3% == 1 (ECHO Match) ELSE (ECHO SiteC2 FAIL)
ECHO --
FOR /F "tokens=1,3 delims= " %%A IN ('findstr "static" "O:\temp_log.txt"') DO IF "%%A"=="192.168.0.14" ECHO %%A = %%B && SET /A var4 = 1
IF %var4% == 1 (ECHO Match) ELSE (ECHO SiteC2 FAIL)
ECHO --
FOR /F "tokens=1,3 delims= " %%A IN ('findstr "static" "O:\temp_log.txt"') DO IF "%%A"=="192.168.0.15" ECHO %%A = %%B && SET /A var5 = 1
IF %var5% == 1 (ECHO Match) ELSE (ECHO SiteC5 FAIL)
ECHO --
FOR /F "tokens=1,3 delims= " %%A IN ('findstr "static" "O:\temp_log.txt"') DO IF "%%A"=="192.168.0.16" ECHO %%A = %%B && SET /A var6 = 1
IF %var6% == 1 (ECHO Match) ELSE (ECHO SiteC6 FAIL)
ECHO.
ECHO.
pause
謝謝你的幫助。這開啓了一種全新的觀察腳本的方式。 – user2881189