本人小白,以下代码都是自己网上找的进行修改,单一网卡可以循环进行修改,但我的环境有4张网卡,我需要循环进行修改所有网卡,直到都能ping通远端ip,输入站代码的变量是有很多条的,这里我只写了一条,能理解就行。
echo off
setlocal enabledelayedexpansion
set /p zdm="请输入站代码:"
if /I %zdm%==111 set name=CZY-LKX-GZZ
for /f "tokens=2 delims==" %%A in ('wmic nic where "NetEnabled='TRUE'" get NetConnectionID /value^|find "="') do (
set /a m+=1
set "winx!m!=%%A"
)
for /f "delims=:" %%i in ('findstr /n /b /e ::::.*:::: "%~f0"') do (
for /f "tokens=1,2,3,4,5,6,7" %%i in ('more /e +%%i "%~f0" ^| find /i "%name%"') do (
set "name=%%i" & set "ip=%%j" & set "gateway=%%k" & set "mask=%%l" & set "newnetwork name=%%m" & set "yuanduan=%%n"
)
)
set minvalue=1000
set maxvalue=4000
:A
if %minvalue% gtr %maxvalue% (
netsh interface ip set address %winx1% dhcp
exit
)
netsh interface ip set address %winx1% static %ip% %mask% %gateway%
ping %yuanduan% -n 5 |findstr "TTL" >nul
if %errorlevel%==1 (
set /a "minvalue+=1000"
for /f "delims=:" %%i in ('findstr /n /b /e ::::.*:::: "%~f0"') do (
for /f "tokens=1,2,3,4,5,6,7" %%i in ('more /e +%%i "%~f0" ^| find /i "%minvalue%"') do (
set "name=%%i" & set "ip=%%j" & set "gateway=%%k" & set "mask=%%l" & set "newnetwork name=%%m" & set "yuanduan=%%n"
)
)
goto A
) else (netsh interface set interface name="%winx1%" newname="%newnetwork name%" >nul && echo 网卡名称”%winx1%“修改为”%newnetwork name%“成功。 )
pause
::::ip信息表::::
名称 ip 网关 掩码 网卡名称 远端IP
CZY-LKX-GZZ 10.10.10.2 10.10.10.65 255.255.255.192 A 10.10.10.20
1000 192.168.1.10 0.0.0.0 255.255.255.0 B 192.168.1.2
2000 192.168.11.10 0.0.0.0 255.255.255.0 C 192.168.11.2
3000 192.168.2.10 0.0.0.0 255.255.255.0 D 192.168.2.2作者: _avatar_ 时间: 2024-1-8 19:12