@echo off
:: A script to assign incremental fix ips to Thin Clients
:: Needs psexec (http://live.sysinternals.com/psexec.exe) in order to run with administrative rights
:: 2013/07/04 neXt (s@xxxxxxxx.com) Initial release
:: set variables
setlocal
set user=Administrator
set pass=Administrator
set iprange=192.168.3
set nmask=255.255.255.0
set gateway=192.168.3.254
set dns1=192.168.3.3
set dns2=192.168.1.3
set startip=200
:: we need a common location to save the last used IP.
set "conf=ips.txt"
IF not EXIST %conf% (
echo DEBUG: Config file does not exist! Creating %conf% with the starting IP %iprange%.%startip%
(echo %startip%)>"%conf%"
)
:: get the saved IP and increment it by 1
for /f "usebackq delims=." %%N in ("%conf%") do set /a newip=%%N+1
if %newip% GTR 254 (
echo IP can not be bigger than 254! Please Check the IP Range!
pause
exit /B
)
:: put back the new IP
(echo %newip%)>"%conf%"
:: in order to change the IP, we need to identify the local network adapter name
For /f "skip=2 tokens=4*" %%a In ('NetSh Interface IPv4 Show Interfaces') Do (
Call :UseNetworkAdapter %%a "%%b"
)
Goto :End
:UseNetworkAdapter
:: varibles: %1 = State; %2 = Name (quoted); %~2 = Name (unquoted)
If %1==connected (
:: Ignore Loopback interface
echo.%2|findstr /C:"Loop" >nul 2>&1
if errorlevel 1 (
echo DEBUG: Interface: %2 IP: %iprange%.%newip% Mask: %nmask% GW: %gateway% DNS: %dns1% %dns2%
psexec -u %user% -p %pass% netsh interface ip set address name=%2 static %iprange%.%newip% %nmask% %gateway% 1
psexec -u %user% -p %pass% netsh interface ip set dns name=%2 static %dns1%
psexec -u %user% -p %pass% netsh interface ip add dns name=%2 %dns2% index=2
:: save the thin client state and reboot
psexec -u %user% -p %pass% ewfmgr c: -commit
psexec -u %user% -p %pass% shutdown -r -f -t 2
))
:End
endlocal
In the void is virtue, and no evil. Wisdom has existance, principle has existance, the Way has existance, spirit is nothingness.
No comments:
Post a Comment