Ich habe versucht, mit dem Befehl set/p die statische IP-Adresse mit dem folgenden Befehl festzulegen. Aber wie füge ich den Befehl add ein, mit dem ich auf der Registerkarte „Erweitert“ mehrere IP-Bereiche hinzufügen kann?
Das heißt, meine statische IP ist 192.168.4.250
, aber mein IP-Bereich ist192.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%
was dazu führt
Außerdem ist die IP-Variable das 3. Oktett 192.168.%A.255
, ich möchte aber auch das 1. und 2. Oktett in eine Variable ändern. Wie mache ich das, wenn der von mir verwendete Befehl lautet %A IN (120,1,130)
?
Antwort1
Ich bin nicht 100 % sicher, ob ich Ihre Frage verstanden habe,
aber ich bin 100 % sicher, dass mein Englisch schwach/mangelhaft ist, tut mir leid ...
Wie dem auch sei, ich hoffe, ich bin nicht weit von dem entfernt, was Ihnen helfen würde …
@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
- Bem.:Ich denke, der zusätzliche Befehl wäre nützlich, um die Konnektivität mit der neu zugewiesenen IP zu testen und die Schleife zu verlassen, wenn das Ergebnis erfolgreich ist:
@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