我嘗試使用 set/p 命令透過以下命令設定靜態 IP 位址。但是如何包含允許我在“高級”選項卡中添加多個 IP 範圍的添加命令?
意思是我的靜態IP是192.168.4.250
,但我的IP範圍是192.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%
這導致
另外,IP 變數是第三個八位元組192.168.%A.255
,但我也想將第一個和第二個八位元組更改為變量,如果我使用的命令是,我該怎麼做%A IN (120,1,130)
?
答案1
我不是 100% 確定我是否理解你的問題,
但我 100% 確定我的英語很弱/很差,抱歉......
無論如何,希望我離對你有幫助的地方不遠......
@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
- 觀察:我認為附加命令對於測試與新分配的 ip 的連接非常有用,如果成功則退出循環:
@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