SET variable in IF statement
Posted: 16 Nov 2016 12:31
I'm trying to figure out why the SET command in an IF statement will not change. The script just displays the IP address, subnet mask, and gateway. It also logs the results in a txt file.
The result I get is:
I don't get the actual subnet mask or gateway correct. I would like to get the correct information for both. Thanks.
Code: Select all
:@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET LOG="C:\LOGS\IPMATCH.TXT"
SET "i=0"
::STORE FILENAMES INTO CONFIG ARRAY
FOR /F "TOKENS=2 DELIMS=:" %%b in ('IPCONFIG^|FINDSTR /I "IPV4 SUBNET GATEWAY"') DO (
SET CONFIG[!i!]=%%b & SET /A "i+=1"
)
::DISPLAY ALL CONFIG ARRAY ITEMS
SET CONFIG
ECHO.===================================
::PRINT ARRAY ITEMS (FROM 0 TILL N)
SET "len=!i!"
SET "i=0"
:LOOP1
ECHO|SET /P="Found IP address:!CONFIG[%i%]!" >> %LOG%
ECHO|SET /P="Found IP address:!CONFIG[%i%]!"
ECHO.
::The problem starts here.
IF !CONFIG[%i%]! EQU !CONFIG[%i%]! (ECHO IP ADDRESS IS: !CONFIG[%i%]!
SET /A "i+=1"
ECHO|SET /P=SUBNET MASK IS: !CONFIG[%i%]!" >> %LOG%
ECHO|SET /P="SUBNET MASK IS: !CONFIG[%i%]!"^ & SET /A "i+=1"
ECHO with GATEWAY OF : !CONFIG[%i%]!>> %LOG%
ECHO with GATEWAY OF : !CONFIG[%i%]!
ECHO.) ELSE (ECHO IP DOESN'T MATCH
SET /A "i+=2"
ECHO.)
SET /A "i+=1"
ECHO.
IF %i% NEQ %len% GOTO LOOP1
The result I get is:
Code: Select all
IP ADDRESS IS: 192.168.1.100
SUBNET MASK IS: 192.168.1.100 with GATEWAY OF: 192.168.1.100
I don't get the actual subnet mask or gateway correct. I would like to get the correct information for both. Thanks.