我是批处理新手,需要一些关于如何使我的脚本更短的指导......它工作正常,但有很多重复的行。
该脚本将'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