Advertisement
J2897

Static LAN IP

Nov 8th, 2015
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.08 KB | None | 0 0
  1. :: Released under the GNU General Public License version 3 by J2897.
  2.  
  3. :: This script will set a static IP address.
  4.  
  5. @echo OFF
  6. setlocal
  7. ver | find "Version 6." > nul
  8. if %ERRORLEVEL% == 0 (
  9.     REM Do OPENFILES to check for administrative privileges
  10.     openfiles >nul
  11.     if errorlevel 1 (
  12.         color cf
  13.         echo.Right-click on this file and select 'Run as administrator'.
  14.         endlocal
  15.         pause
  16.         color
  17.         exit /b 1
  18.     )
  19. )
  20.  
  21. REM Custom variables.
  22. set "NET_NAME=Local Area Connection"
  23. set "IP=192.168.0.3"
  24. set "SUBNET_MASK=255.255.255.0"
  25. set "GATEWAY=192.168.0.1"
  26. set "DNS1=%GATEWAY%"
  27. set "DNS2=8.8.8.8"
  28.  
  29. echo Setting static IP . . .
  30. netsh interface ip set address name="%NET_NAME%" static %IP% %SUBNET_MASK% %GATEWAY%
  31.  
  32. echo Setting primary DNS server . . .
  33. netsh interface ip set dns name="%NET_NAME%" static %DNS1%
  34.  
  35. echo Setting secondary DNS server . . .
  36. netsh interface ip add dns name="%NET_NAME%" %DNS2% index=2
  37.  
  38. REM Revert to DHCP.
  39. :: netsh interface ip set address name="%NET_NAME%" source=dhcp
  40.  
  41. :End
  42. endlocal
  43. echo.
  44. echo Ending . . .
  45. pause
  46. timeout /t 10 /nobreak >nul
  47. exit /b 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement