¿Cómo agrego rangos de IP en un archivo por lotes después de configurar un comando para establecer una dirección IP?

¿Cómo agrego rangos de IP en un archivo por lotes después de configurar un comando para establecer una dirección IP?

Intenté usar el comando set/p para configurar la dirección IP estática usando el siguiente comando. Pero, ¿cómo incluyo el comando Agregar que me permite agregar múltiples rangos de IP en la pestaña Avanzar?

Lo que significa que mi IP estática es 192.168.4.250 pero mi rango de IP es192.168.4.250 - 192.168.60.250

@echo off
echo ipv4 set address "Ethernet 3"
echo ipv4 netsh interface name="Ethernet 3"
set/p address=First Address:
set/p mask=First Mask:
set/p gate=First Gate:
netsh interface ipv4 set address name="Ethernet 3" static %address% %mask% %gate%

lo que resulta en

ingrese la descripción de la imagen aquí

Además, la variable IP es el tercer octeto 192.168.%A.255, pero también quiero cambiar el primer y el segundo octeto a una variable. ¿Cómo lo hago si el comando que uso es %A IN (120,1,130)?

Respuesta1

No estoy 100% seguro de haber entendido tu pregunta,
pero sí estoy 100% seguro de que mi inglés es débil/pobre, lo siento...

De todos modos, espero no estar lejos de lo que podría ayudarte...

@echo off && setlocal EnableDelayedExpansion

echo;iPv4 Set address "Ethernet 3" & echo;iPv4 netsh interface name="Ethernet 3"

:loop
cls & echo 

:: remove variable/value in using loop for command set "_var="
for %%i in ("address=", "mask=","gate=","dns1=","dns2=")do set "%%~i"

:: set variable/value in using loop for command to set /p "_var=Test to Screen" 
for %%i in ("address=First Address: ", "mask=First Mask: ","gate=First Gate: ","dns1=First DNS: ","dns2=Second DNS: "
     )do <con: set /p "_%%~i" || goto :loop

:: set variable/value in using loop for command set dns/ip 1st and 2nd
for %%i in (1.1.1.1,"1.0.0.1 index=2")do %__AppDir__%netsh.exe interface ipv4 add dns %%~i

:: set variable/value in using loop for command set "Ethernet 3" static ip/mask/gate
%__AppDir__%netsh.exe interface ipv4 set address name="Ethernet 3" static %_address% %_mask% %_gate%

rem For /L (1ST.IPV4.OCT.IP)do ...
for /L %%A in (198,1,200
    )do %__AppDir__%netsh.exe interface ipv4 set address name="Ethernet 3" static %%~A.128.60.255 %_mask% %_gate%

rem For /L (1ST.2ND.IPV4.OCT)do... and Set %%A.2ND.IPV4.OCT
for /L %%A in (198,1,200)do for /l %%B in (128,1,130
     )do %__AppDir__%netsh.exe interface ipv4 set address name="Ethernet 3" static %%~A.%%~B.60.255 %_mask% %_gate%
        
rem For /L (1ST.2ND.3RD.OCT)do ... and Set %%A.%%B.%%C.OCT
for /L %%A in (198,1,200)do for /l %%B in (128,1,130)do for /l %%C in (4,1,60
    )do %__AppDir__%netsh.exe interface ipv4 set address name="Ethernet 3" static %%~A.%%~B.%%~C.255 %_mask% %_gate% 

rem For /L (1ST.2ND.3RD.4TH)do ... and Set %%A.%%B.%%C.%%D
for /L %%A in (198,1,200)do for /l %%B in (128,1,130)do for /l %%C in (4,1,60)do for /l %%D in (253,1,254
     )do %__AppDir__%netsh.exe interface ipv4 set address name="Ethernet 3" static %%~A.%%~B.%%~C.%%~D %_mask% %_gate%

endlocal & goto :eof || exit /b 0 

  • Obs.:Creo que el comando adicional sería útil para probar la conectividad con la IP recién asignada y salir del bucle si tiene éxito:
@echo off && setlocal EnableDelayedExpansion

echo;iPv4 Set address "Ethernet 3" & echo;iPv4 Netsh Interface Name="Ethernet 3"

:loop
cls & echo; & for %%i in ("address=", "mask=","gate=","dns1=","dns2=")do set "%%~i"

for %%i in ("address=First Address: ", "mask=First Mask: ","gate=First Gate: ","dns1=First DNS: ","dns2=Second DNS: "
     )do <con: set /p "_%%~i" || goto :loop

for %%i in (1.1.1.1,"1.0.0.1 index=2")do %__AppDir__%netsh.exe interface ipv4 add dns %%~i
%__AppDir__%netsh.exe interface ipv4 set address name="Ethernet 3" static %_address% %_mask% %_gate%

for /L %%A in (198,1,200
    )do ;"%__AppDir__%netsh.exe" interface ipv4 set address name="Ethernet 3" static %%~A.128.60.255 %_mask% %_gate% && (
         <con: %__AppDir__%ping.exe 1.1.1.1 -f -4 -w 4|2>nul %__AppDir__%findstr.exe .*Received.=.[1-4].>nul && goto %:^)
        ) 

for /L %%A in (198,1,200)do for /l %%B in (128,1,130
     )do %__AppDir__%netsh.exe interface ipv4 set address name="Ethernet 3" static %%~A.%%~B.60.255 %_mask% %_gate% && (
         <con: %__AppDir__%ping.exe 1.1.1.1 -f -4 -w 4|2>nul %__AppDir__%findstr.exe "Received.=.[1-4]">nul && goto %:^)
        )
        
for /L %%A in (198,1,200)do for /l %%B in (128,1,130)do for /l %%C in (4,1,60
    )do %__AppDir__%netsh.exe interface ipv4 set address name="Ethernet 3" static %%~A.%%~B.%%~C.255 %_mask% %_gate% && (
         <con: %__AppDir__%ping.exe 1.1.1.1 -f -4 -w 4|2>nul %__AppDir__%findstr.exe "Received.=.[1-4]" >nul && goto %:^)
        )
        
for /L %%A in (198,1,200)do for /l %%B in (128,1,130)do for /l %%C in (4,1,60)do for /l %%D in (253,1,254
     )do ;%__AppDir__%netsh.exe interface ipv4 set address name="Ethernet 3" static %%A.%%B.%%C.%%D %_mask% %_gate% && (
         <con: %__AppDir__%ping.exe 1.1.1.1 -f -4 -w 4|2>nul %__AppDir__%findstr.exe "Received.=.[1-4]">nul && goto %:^)
        )
%:^) 
:: Your next command came here...
endlocal & goto :eof || exit /b 0

información relacionada