Certainly! Here's your script translated into English, along with adjustments to address the issue of not finding interfaces due to the Russian language settings on your Windows system.
@echo off
REM This script requires administrator privileges
REM Check for administrator rights
net session >nul 2>&1
if %errorLevel% NEQ 0 (
echo Please run this script as an administrator.
pause
exit /b
)
REM Enable delayed variable expansion
setlocal EnableDelayedExpansion
echo Retrieving list of network interfaces...
REM Initialize interface counter
set interfaceCount=0
REM Get list of connected network interfaces
for /f "skip=2 tokens=2 delims=:" %%A in ('netsh interface show interface ^| findstr /I "Connected"') do (
set /a interfaceCount+=1
for /f "tokens=*" %%B in ("%%A") do (
set "interfaceName[!interfaceCount!]=%%B"
)
)
if %interfaceCount% EQU 0 (
echo No connected network interfaces found.
pause
exit /b
)
echo.
echo Assigning new IP addresses to network interfaces...
REM Base components of the IP address
set baseIP=192.168.0.
set /a ipOctet=2
REM Assign new IP addresses and get gateways
for /l %%i in (1,1,%interfaceCount%) do (
set "name=!interfaceName[%%i]!"
REM Get the current gateway IP address for this interface
for /f "tokens=2 delims=:" %%G in ('netsh interface ip show config name^="!name!" ^| findstr /R "Default Gateway"') do (
set "gatewayIP=%%G"
)
REM Remove extra spaces
set "gatewayIP=!gatewayIP:~1!"
REM Check if gateway was found
if "!gatewayIP!"=="" (
echo Failed to find the gateway IP address for interface "!name!".
echo Skipping interface.
set /a ipOctet+=1
goto :continue
)
REM Assign new IP address
set "ipAddress=%baseIP%!ipOctet!"
set /a ipOctet+=1
echo Configuring interface "!name!"...
echo New IP address: !ipAddress!
echo Subnet mask: 255.255.255.0
echo Default gateway (modem IP): !gatewayIP!
REM Set the new IP, subnet mask, and gateway
netsh interface ip set address name="!name!" static !ipAddress! 255.255.255.0 !gatewayIP!
REM Save assigned IP and gateway for output
set "assignedIP[%%i]=!ipAddress!"
set "gatewayIP[%%i]=!gatewayIP!"
:continue
)
echo.
echo All interfaces have been assigned new IP addresses.
REM Display list of interfaces with their new IPs and gateways
echo.
echo List of interfaces with their new IP addresses and gateways:
echo.
for /l %%i in (1,1,%interfaceCount%) do (
echo %%i) !interfaceName[%%i]! - IP: !assignedIP[%%i]!, Gateway: !gatewayIP[%%i]!
)
REM Prompt user to select the default interface for traffic
echo.
echo Please select the interface that will be used by default for all traffic:
set /p selectedInterface=Enter the interface number:
REM Validate user input
if %selectedInterface% LSS 1 (
echo Invalid selection.
pause
exit /b
)
if %selectedInterface% GTR %interfaceCount% (
echo Invalid selection.
pause
exit /b
)
REM Configure gateways and interface metrics
echo.
echo Configuring interface metrics...
for /l %%i in (1,1,%interfaceCount%) do (
set "name=!interfaceName[%%i]!"
set "ipAddress=!assignedIP[%%i]!"
set "gatewayIP=!gatewayIP[%%i]!"
if "%%i"=="%selectedInterface%" (
echo Setting low metric on interface "!name!" for priority
netsh interface ip set interface name="!name!" metric=10
) else (
echo Setting higher metric on interface "!name!" to lower priority
netsh interface ip set interface name="!name!" metric=50
)
)
echo.
echo Network interface settings have been updated.
echo.
echo You can now access the modem web interfaces via their gateway IP addresses.
echo.
pause
Explanation of the Issue:
The script is not finding network interfaces because it's searching for the English word "Connected" in the output of netsh interface show interface, but your Windows system is in Russian. This means the output of the command is also in Russian, and the word "Connected" does not appear.
Steps to Fix the Issue:
-
Adjust Search Strings for Russian Output:
Replace "Connected" with the Russian equivalent for "Connected" as it appears in your system's output. For example, if the Russian word for "Connected" is "Подключен" (which is "Connected" in Russian), you should modify the findstr command accordingly.
-
Modify the Script for Localization:
Update the script to use the localized terms in your language. Here's the updated section of the script with adjustments for Russian output:
REM Get list of connected network interfaces
for /f "skip=3 tokens=1,2,3,4 delims= " %%A in ('netsh interface show interface') do (
if "%%D"=="Связано" (
set /a interfaceCount+=1
set "interfaceName[!interfaceCount!]=%%C"
)
)
Alternatively, you can modify the script to avoid relying on language-specific output by using more consistent parsing methods.
Updated Script for Russian Windows:
@echo off
REM This script requires administrator privileges
REM Check for administrator rights
net session >nul 2>&1
if %errorLevel% NEQ 0 (
echo Please run this script as an administrator.
pause
exit /b
)
REM Enable delayed variable expansion
setlocal EnableDelayedExpansion
echo Retrieving list of network interfaces...
REM Initialize interface counter
set interfaceCount=0
REM Get list of connected network interfaces
for /f "skip=3 tokens=1,2,3,4 delims= " %%A in ('netsh interface show interface') do (
if "%%D"=="Подключено" (
set /a interfaceCount+=1
set "interfaceName[!interfaceCount!]=%%C"
)
)
if %interfaceCount% EQU 0 (
echo No connected network interfaces found.
pause
exit /b
)
REM Rest of the script remains the same...
Explanation:
- The
netsh interface show interface command outputs a table of interfaces with their statuses.
- By adjusting the
for /f options and tokens, we can parse the output more reliably.
- The
skip=3 option skips the first three lines, which are header information.
- We use
tokens=1,2,3,4 delims= to split the line into tokens based on spaces.
- Then, we check if the fourth token (
%%D) is "Подключено" (which means "Connected" in Russian).
- If it is, we proceed to add that interface to our list.
Alternative Approach Using WMIC:
WMIC commands can provide language-independent outputs. Here's how you can modify the script to use WMIC to get the list of connected interfaces:
REM Get list of connected network interfaces
for /f "skip=1 tokens=1,* delims==" %%A in ('wmic nic where "NetEnabled=True" get NetConnectionID /value') do (
if not "%%B"=="" (
set /a interfaceCount+=1
set "interfaceName[!interfaceCount!]=%%B"
)
)
Explanation:
wmic nic where "NetEnabled=True" get NetConnectionID /value retrieves the names of enabled network interfaces.
- This method does not depend on the system language.
Recommendation:
For the script to be language-independent and work regardless of the system language, I recommend using WMIC or PowerShell commands that are not affected by localization.
Final Script Using WMIC:
@echo off
REM This script requires administrator privileges
REM Check for administrator rights
net session >nul 2>&1
if %errorLevel% NEQ 0 (
echo Please run this script as an administrator.
pause
exit /b
)
REM Enable delayed variable expansion
setlocal EnableDelayedExpansion
echo Retrieving list of network interfaces...
REM Initialize interface counter
set interfaceCount=0
REM Get list of connected network interfaces using WMIC
for /f "tokens=*" %%A in ('wmic nic where "NetEnabled=True" get NetConnectionID ^| findstr /V "NetConnectionID"') do (
if not "%%A"=="" (
set /a interfaceCount+=1
set "interfaceName[!interfaceCount!]=%%A"
)
)
if %interfaceCount% EQU 0 (
echo No connected network interfaces found.
pause
exit /b
)
echo.
echo Assigning new IP addresses to network interfaces...
REM Base components of the IP address
set baseIP=192.168.0.
set /a ipOctet=2
REM Assign new IP addresses and get gateways
for /l %%i in (1,1,%interfaceCount%) do (
set "name=!interfaceName[%%i]!"
REM Get the current gateway IP address for this interface
for /f "tokens=2 delims=:" %%G in ('netsh interface ip show config name^="!name!" ^| findstr /R "Default Gateway\|Основной шлюз"') do (
set "gatewayIP=%%G"
)
REM Remove extra spaces
set "gatewayIP=!gatewayIP:~1!"
REM Check if gateway was found
if "!gatewayIP!"=="" (
echo Failed to find the gateway IP address for interface "!name!".
echo Skipping interface.
set /a ipOctet+=1
goto :continue
)
REM Assign new IP address
set "ipAddress=%baseIP%!ipOctet!"
set /a ipOctet+=1
echo Configuring interface "!name!"...
echo New IP address: !ipAddress!
echo Subnet mask: 255.255.255.0
echo Default gateway (modem IP): !gatewayIP!
REM Set the new IP, subnet mask, and gateway
netsh interface ip set address name="!name!" static !ipAddress! 255.255.255.0 !gatewayIP!
REM Save assigned IP and gateway for output
set "assignedIP[%%i]=!ipAddress!"
set "gatewayIP[%%i]=!gatewayIP!"
:continue
)
echo.
echo All interfaces have been assigned new IP addresses.
REM Display list of interfaces with their new IPs and gateways
echo.
echo List of interfaces with their new IP addresses and gateways:
echo.
for /l %%i in (1,1,%interfaceCount%) do (
echo %%i) !interfaceName[%%i]! - IP: !assignedIP[%%i]!, Gateway: !gatewayIP[%%i]!
)
REM Prompt user to select the default interface for traffic
echo.
echo Please select the interface that will be used by default for all traffic:
set /p selectedInterface=Enter the interface number:
REM Validate user input
if %selectedInterface% LSS 1 (
echo Invalid selection.
pause
exit /b
)
if %selectedInterface% GTR %interfaceCount% (
echo Invalid selection.
pause
exit /b
)
REM Configure gateways and interface metrics
echo.
echo Configuring interface metrics...
for /l %%i in (1,1,%interfaceCount%) do (
set "name=!interfaceName[%%i]!"
set "ipAddress=!assignedIP[%%i]!"
set "gatewayIP=!gatewayIP[%%i]!"
if "%%i"=="%selectedInterface%" (
echo Setting low metric on interface "!name!" for priority
netsh interface ip set interface name="!name!" metric=10
) else (
echo Setting higher metric on interface "!name!" to lower priority
netsh interface ip set interface name="!name!" metric=50
)
)
echo.
echo Network interface settings have been updated.
echo.
echo You can now access the modem web interfaces via their gateway IP addresses.
echo.
pause
Notes:
- In the
for /f loop that retrieves the gateway IP, I've added support for both English and Russian outputs by using findstr /R "Default Gateway\|Основной шлюз".
- This ensures the script picks up the gateway line regardless of the system language.
Testing the Script:
- Run the script in a test environment to ensure it works as expected.
- Check the outputs at each step to confirm that interfaces are being found and configured correctly.
Conclusion:
By adjusting the script to use language-independent commands or accommodating localization in the search strings, you can ensure that the script functions correctly on a Russian Windows system. The provided script should now find the network interfaces and perform the desired configurations.