add additional IP
-7
Add additional IP to compute
@Echo off
goto :MAIN
::** Begin Script AssignNewIP **
:MAIN
:: Get the NIC driver from the registry
for /f "delims= tokens=3" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\1\ServiceName"') do (
set NET_DRIVER=%%i
)
:: Get the IP address from the registry
for /f "delims= tokens=3" %%i in ('reg query "HKLM\SYSTEM\CurrentControlSet\Services\%NET_DRIVER%\Parameters\Tcpip\IPAddress2"') do (
set IP_ADD=%%i
)
:: If multiple addresses assigned, abort
for /f %%i in ('echo %%IP_ADD%% ^| findstr ";"') do goto :END
:: Break IP address into octets
for /f "delims=. tokens=1-4" %%w in ('echo %%IP_ADD%%') do (
set /a w=%%w
set /a x=%%x
set /a y=%%y+1
set /a z=%%z
)
:: If new IP address is being used, abort
for /f %%i in ('ping %w%.%x%.%y%.%z% ^| findstr "Reply from"') do goto
:END
:: Update registry to add new IP address
reg update "HKLM\SYSTEM\CurrentControlSet\Services\%NET_DRIVER%\Parameters\Tcpip\IPAddress2=%IP_ADD%;%w%.%x%.%y%.%z%" > nul
:: Get the subnet mask from the registry and set new subnet masks
for /f "delims= tokens=3" %%i in ('reg query
"HKLM\SYSTEM\CurrentControlSet\Services\%NET_DRIVER%\Parameters\Tcpip\SubnetMask2"') do (
reg update "HKLM\SYSTEM\CurrentControlSet\Services\%NET_DRIVER%\Parameters\Tcpip\SubnetMask2=%%i;%%i" > nul
)
:: Get the default gateway IP address from the registry and set new
default gateways
for /f "delims= tokens=3" %%i in ('reg query "HKLM\SYSTEM\CurrentControlSet\Services\%NET_DRIVER%\Parameters\Tcpip\DefaultGateway2"') do (
for /f "delims=. tokens=1-4" %%w in ('echo %%i') do (
set /a y=%%y+1
reg update "HKLM\SYSTEM\CurrentControlSet\Services\%NET_DRIVER%\Parameters\Tcpip\DefaultGateway2=%%i;%%w.%%x.%y%.%%z" > nul
)
)
:END
set NET_DRIVER=
set IP_ADD=
set w=
set x=
set y=
set z=






Bobby R Ward
---------------------
bobbyrward@gmail.com