我的公司不对员工的计算机使用DHCP,所以我必须手动键入所有内容。所以我想为这个写一个简单的脚本会很好。
问题是指定我想要配置的接口。我想要一个小菜单,在那里我可以简单地选择设备。菜单实际上是有效的,但问题是最后有一些不必要的空格,我没有去掉它。
(%IP%
和%Gateway%
在其他逻辑中定义。)
这是我目前所拥有的:
@setlocal enableextensions enabledelayedexpansion
set /P Gateway="Welcher Gateway? "
set /P IP="Welche IP? "
echo --------------------------------
echo NR. Schnittstellenname
echo --------------------------------
SET countST=1
for /f "tokens=4-10" %%a in ('netsh interface show interface') do (
echo !countST!. %%a %%b %%c %%d %%e
set /a countST+=1
)
SET /P numberST="Welche Schnittstelle soll konfiguriert werden? (NR) "
SET countST=1
for /f "tokens=4-10" %%a in ('netsh interface show interface') do (
if !countST!==%numberST% (
set ST="%%a %%b %%c %%d %%e"
)
set /a countST+=1
)
echo %ST%
netsh interface ipv4 set address name=%ST% static %IP% 255.255.255.0 %Gateway% store=persistent
netsh interface ipv4 set dnsservers name=%ST% source=static address="8.8.8.8" validate=no
netsh interface ipv4 add dnsservers name=%ST% address="1.1.1.1" validate=no index=2
PAUSE
endlocal
发布于 2021-05-25 21:15:23
我已经尝试过这样的方法,但不知何故不起作用:
@setlocal enableextensions enabledelayedexpansion
set countST=1
echo off
for /f "tokens=4-10" %%a in ('netsh interface show interface') do (
if "%e%"==" " (
if "%d%"==" " (
if "%c%"==" " (
if "%b%"==" " (
echo %%a
pause
) else (
echo %%a %%b
pause
)
) else (
echo %%a %%b %%c
pause
)
) else (
echo %%a %%b %%c %%d
pause
)
) else (
echo %%a %%b %%c %%d %%e
)
)
pause
https://stackoverflow.com/questions/67688521
复制相似问题