NoWar
NoWar

Reputation: 37633

How to verify user input command line

Somehow I need to verify user input so in case in error user has return to inpu 2 times correct values.

Also would be great to prevent empty input as well by Enter.

Is it possible to do it in a batch file in MS Windows?

@ECHO OFF
set /p ip=IP Address:
set /p mask=Network Mask:
set /p gate=Port:
timeout /t 3
netsh interface ip set address "Local Area Connection" static %ip% %mask% %gate% 1
ECHO Done
timeout /t 3
ipconfig
timeout /t 3
EXIT

Upvotes: 1

Views: 88

Answers (1)

NoWar
NoWar

Reputation: 37633

I did like this...

@ECHO OFF
color 17
ECHO ----------------------------
ECHO Configuracion de IPs
ECHO ----------------------------

:STARTINPUT
set ip=NOTOK
set mask=NOTOK
set gate=NOTOK
rem --------------------------------------------------------------------
set /p ip1=Direccion IP :
set /p ip2=Verificar el Direccion IP :
If %ip1%==%ip2% (
   ECHO Verificado: %ip1%
   set ip=OK
   GOTO MASKINPUT
) else (
ECHO Direccion IP "%ip1%" no ha sido verificado!!!
GOTO STARTINPUT
)
rem --------------------------------------------------------------------
:MASKINPUT
set /p mask1=Mascara de red :
set /p mask2=Verificar el mascara de red :
If %mask1%==%mask2% (
   ECHO Verificado: %mask1%
   set mask=OK
   GOTO GATEINPUT
) else (
      ECHO Mascara de red "%mask1%" no ha sido verificado!!!
      GOTO MASKINPUT
)
rem --------------------------------------------------------------------
:GATEINPUT
set /p gate1=Puerta de enlace:
set /p gate2=Verificar el puerta de enlace:
If %gate1%==%gate2% (
    ECHO Verificado: %gate1%
    set gate=OK

    rem timeout /t 3
    ECHO Cambiando direcciones...
    netsh interface ip set address "Local Area Connection" static %ip% %mask% %gate% 1
    ECHO Completado
    timeout /t 3
    ipconfig
    timeout /t 3
    rem EXIT

) else (
      ECHO Puerta "%gate1%" no ha sido verificado!!!
      GOTO GATEINPUT
)

Upvotes: 1

Related Questions