Let everyone laugh, I think there are too many codes, it should still be able to be simplified, but I have low level!
I don't know if the expert can simplify the code!
Also, the subnet mask and backup DNS cannot be displayed, does any expert know how to do it?
@echo off
mode con cols=80 lines=30
:top
title ………………………………………………IP Modifier………………………………………………
cls
color 0a
::::::::::::::::::::::::::::::::::::::::::::::
:Check IP, Gateway, DNS
@echo off
setlocal enabledelayedexpansion
set IP_num=0
set Gateway_num=0
set DNS_num=0
for /f "tokens=2* delims=:" %%i in ('ipconfig /all ^| find /i "IP Address"') do (
for /f "tokens=2* delims=:" %%a in ('ipconfig /all ^| find /i "Default Gateway"') do (
for /f "tokens=2* delims=:" %%1 in ('ipconfig /all ^| find /i "DNS Servers"') do (
set IP_=%%i
set Gateway_=%%a
set DNS_=%%1
if "!IP_num!"=="0" set IP2=!IP_:~1!
if "!Gateway_num!"=="0" set Gateway2=!Gateway_:~1!
if "!DNS_num!"=="0" set DNS2=!DNS_:~1!
set /a IP_num=!IP_num!+1
set /a Gateway_num=!Gateway_num!+1
set /a DNS_num=!DNS_num!+1
)
)
)
CLS
::::::::::::::::::::::::::::::::::::::::::::::
echo.
echo IP Modifier QQ:82288252
echo ================================================================================
echo Local Information:
echo Computer Name: %userdomain%
echo Local IP: %IP2%
echo Local Gateway: %Gateway2%
echo Local DNS: %DNS2%
echo.
set /p n= Enter local number (Q to quit):
if %n% equ q exit
echo.
echo The number you entered is: %n%
echo.
set /p x= How many bits to offset the IP number:
set /a ip = %n% + %x%
echo.
echo Modifying, please wait...
::::::::::::::::::::::::::::::::::::::::::::::
:Generate VBS script to modify IP
echo strIPAddress = Array(^"192.168.1.%IP%^") ^'Modified ip >>ip.vbe
echo strSubnetMask = Array(^"255.255.255.0^") ^'Subnet mask >>ip.vbe
echo strGateway = Array(^"192.168.1.1^") ^'Gateway >>ip.vbe
echo arrDNSServers = Array(^"202.103.224.68^", ^"202.103.225.68^")^'DNS >>ip.vbe
echo strComputer = ^".^" >>ip.vbe
echo. >>ip.vbe
echo Set objWMIService = GetObject(^"winmgmts:^\\^" ^& strComputer ^& ^"^\root^\cimv2^") >>ip.vbe
echo Set colNetAdapters = objWMIService.ExecQuery _ >>ip.vbe
echo (^"Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE^") >>ip.vbe
echo. >>ip.vbe
echo For Each objNetAdapter in colNetAdapters >>ip.vbe
echo sip=objNetAdapter.IPAddress >>ip.vbe
echo ^'strIPAddress = sip ^'Keep original ip >>ip.vbe
echo. >>ip.vbe
echo strGatewayMetric = Array(1) >>ip.vbe
echo errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) >>ip.vbe
echo errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) >>ip.vbe
echo errDNS=objNetAdapter.SetDNSServerSearchOrder(arrDNSServers) >>ip.vbe
echo exit for ^'Only modify the settings of the first network card >>ip.vbe
echo Next >>ip.vbe
::::::::::::::::::::::::::::::::::::::::::::::
:Replace actual computer name with variable %n%
echo Windows Registry Editor Version 5.00 >Computer Name.reg
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters] >>Computer Name.reg
echo "NV Hostname"="%n%" >>Computer Name.reg
echo "Hostname"="%n%" >>Computer Name.reg
::::::::::::::::::::::::::::::::::::::::::::::
:Import registry file
regedit /s Computer Name.reg
::::::::::::::::::::::::::::::::::::::::::::::
:Run VBE file to change IP address
ip.vbe
::::::::::::::::::::::::::::::::::::::::::::::
:Delete reg and vbe files
del Computer Name.reg
del ip.vbe
::::::::::::::::::::::::::::::::::::::::::::::
:Recheck IP, Gateway, DNS
@echo off
setlocal enabledelayedexpansion
set IP_num=0
set Gateway_num=0
set DNS_num=0
for /f "tokens=2* delims=:" %%i in ('ipconfig /all ^| find /i "IP Address"') do (
for /f "tokens=2* delims=:" %%a in ('ipconfig /all ^| find /i "Default Gateway"') do (
for /f "tokens=2* delims=:" %%1 in ('ipconfig /all ^| find /i "DNS Servers"') do (
set IP_=%%i
set Gateway_=%%a
set DNS_=%%1
if "!IP_num!"=="0" set IP2=!IP_:~1!
if "!Gateway_num!"=="0" set Gateway2=!Gateway_:~1!
if "!DNS_num!"=="0" set DNS2=!DNS_:~1!
set /a IP_num=!IP_num!+1
set /a Gateway_num=!Gateway_num!+1
set /a DNS_num=!DNS_num!+1
)
)
)
CLS
::::::::::::::::::::::::::::::::::::::::::::::
echo.
echo IP Modifier QQ:82288252
echo ================================================================================
echo Modification Successful:
echo.
echo Current Local Information:
echo Computer Name: %userdomain% This item takes effect after restart
echo Local IP: %IP2%
echo Local Gateway: %Gateway2%
echo Local DNS: %DNS2%
echo.
:Press any key to exit
@pause
I don't know if the expert can simplify the code!
Also, the subnet mask and backup DNS cannot be displayed, does any expert know how to do it?
@echo off
mode con cols=80 lines=30
:top
title ………………………………………………IP Modifier………………………………………………
cls
color 0a
::::::::::::::::::::::::::::::::::::::::::::::
:Check IP, Gateway, DNS
@echo off
setlocal enabledelayedexpansion
set IP_num=0
set Gateway_num=0
set DNS_num=0
for /f "tokens=2* delims=:" %%i in ('ipconfig /all ^| find /i "IP Address"') do (
for /f "tokens=2* delims=:" %%a in ('ipconfig /all ^| find /i "Default Gateway"') do (
for /f "tokens=2* delims=:" %%1 in ('ipconfig /all ^| find /i "DNS Servers"') do (
set IP_=%%i
set Gateway_=%%a
set DNS_=%%1
if "!IP_num!"=="0" set IP2=!IP_:~1!
if "!Gateway_num!"=="0" set Gateway2=!Gateway_:~1!
if "!DNS_num!"=="0" set DNS2=!DNS_:~1!
set /a IP_num=!IP_num!+1
set /a Gateway_num=!Gateway_num!+1
set /a DNS_num=!DNS_num!+1
)
)
)
CLS
::::::::::::::::::::::::::::::::::::::::::::::
echo.
echo IP Modifier QQ:82288252
echo ================================================================================
echo Local Information:
echo Computer Name: %userdomain%
echo Local IP: %IP2%
echo Local Gateway: %Gateway2%
echo Local DNS: %DNS2%
echo.
set /p n= Enter local number (Q to quit):
if %n% equ q exit
echo.
echo The number you entered is: %n%
echo.
set /p x= How many bits to offset the IP number:
set /a ip = %n% + %x%
echo.
echo Modifying, please wait...
::::::::::::::::::::::::::::::::::::::::::::::
:Generate VBS script to modify IP
echo strIPAddress = Array(^"192.168.1.%IP%^") ^'Modified ip >>ip.vbe
echo strSubnetMask = Array(^"255.255.255.0^") ^'Subnet mask >>ip.vbe
echo strGateway = Array(^"192.168.1.1^") ^'Gateway >>ip.vbe
echo arrDNSServers = Array(^"202.103.224.68^", ^"202.103.225.68^")^'DNS >>ip.vbe
echo strComputer = ^".^" >>ip.vbe
echo. >>ip.vbe
echo Set objWMIService = GetObject(^"winmgmts:^\\^" ^& strComputer ^& ^"^\root^\cimv2^") >>ip.vbe
echo Set colNetAdapters = objWMIService.ExecQuery _ >>ip.vbe
echo (^"Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE^") >>ip.vbe
echo. >>ip.vbe
echo For Each objNetAdapter in colNetAdapters >>ip.vbe
echo sip=objNetAdapter.IPAddress >>ip.vbe
echo ^'strIPAddress = sip ^'Keep original ip >>ip.vbe
echo. >>ip.vbe
echo strGatewayMetric = Array(1) >>ip.vbe
echo errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) >>ip.vbe
echo errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) >>ip.vbe
echo errDNS=objNetAdapter.SetDNSServerSearchOrder(arrDNSServers) >>ip.vbe
echo exit for ^'Only modify the settings of the first network card >>ip.vbe
echo Next >>ip.vbe
::::::::::::::::::::::::::::::::::::::::::::::
:Replace actual computer name with variable %n%
echo Windows Registry Editor Version 5.00 >Computer Name.reg
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters] >>Computer Name.reg
echo "NV Hostname"="%n%" >>Computer Name.reg
echo "Hostname"="%n%" >>Computer Name.reg
::::::::::::::::::::::::::::::::::::::::::::::
:Import registry file
regedit /s Computer Name.reg
::::::::::::::::::::::::::::::::::::::::::::::
:Run VBE file to change IP address
ip.vbe
::::::::::::::::::::::::::::::::::::::::::::::
:Delete reg and vbe files
del Computer Name.reg
del ip.vbe
::::::::::::::::::::::::::::::::::::::::::::::
:Recheck IP, Gateway, DNS
@echo off
setlocal enabledelayedexpansion
set IP_num=0
set Gateway_num=0
set DNS_num=0
for /f "tokens=2* delims=:" %%i in ('ipconfig /all ^| find /i "IP Address"') do (
for /f "tokens=2* delims=:" %%a in ('ipconfig /all ^| find /i "Default Gateway"') do (
for /f "tokens=2* delims=:" %%1 in ('ipconfig /all ^| find /i "DNS Servers"') do (
set IP_=%%i
set Gateway_=%%a
set DNS_=%%1
if "!IP_num!"=="0" set IP2=!IP_:~1!
if "!Gateway_num!"=="0" set Gateway2=!Gateway_:~1!
if "!DNS_num!"=="0" set DNS2=!DNS_:~1!
set /a IP_num=!IP_num!+1
set /a Gateway_num=!Gateway_num!+1
set /a DNS_num=!DNS_num!+1
)
)
)
CLS
::::::::::::::::::::::::::::::::::::::::::::::
echo.
echo IP Modifier QQ:82288252
echo ================================================================================
echo Modification Successful:
echo.
echo Current Local Information:
echo Computer Name: %userdomain% This item takes effect after restart
echo Local IP: %IP2%
echo Local Gateway: %Gateway2%
echo Local DNS: %DNS2%
echo.
:Press any key to exit
@pause

