Advertisement
Altenator_IWnet

Batch DNS Changer

May 20th, 2012
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.89 KB | None | 0 0
  1. @echo off
  2. set dNs=
  3. set gAteWaY=
  4. set MainDNS=
  5. set SecondDNS=
  6. set WifiSecond=
  7. set SecondResult=
  8. set WifiSet=
  9. set WifiOn=
  10. for /f "tokens=15" %%A in ('ipconfig /all ^| find "DNS Servers"') do @set dNs=%%A
  11. for /f "tokens=13" %%A in ('ipconfig ^| find "Gateway"') do @set gAteWaY=%%A
  12. for /f "tokens=2" %%G in ('nslookup 98.139.183.24 ^| find "Server:"') do @set h0stNamE=%%G
  13. :main
  14. echo.
  15. echo DNS Changer
  16. echo Author : AltenatorIWnet
  17. echo Date : 20 May 2012
  18. echo - Support Local Area Network Adapter
  19. echo - Support Wireless Adapter
  20. echo.
  21. echo Knows Bug :
  22. echo - NetSH can't run without administrator privileges..
  23. echo.
  24. echo Note :
  25. echo - I only test this batch in Win7 Ultimate, and i not sure
  26. echo   this batch work on other Windows OS...
  27. echo.
  28. echo.
  29. echo Your Current Main DNS..
  30. echo - %dNs% [ %h0stNamE% ]
  31. echo.
  32. :submit
  33. echo.
  34. echo ---------------------------------------
  35. set /p MainDNS=Your Primary DNS )
  36. echo ---------------------------------------
  37. echo.
  38. echo ---------------------------------------------------------
  39. echo It's ok to leave blank here because secondary almost isn't important
  40. echo.
  41. set /p SecondDNS=Secondary DNS [may leave blank] )
  42. echo ---------------------------------------------------------
  43. goto:checkout
  44. exit
  45. :checkout
  46. IF NOT DEFINED MainDNS (
  47.    cls
  48.    echo.
  49.    echo Please dude, make sure Primary DNS is inserted
  50.    goto:submit
  51.    exit
  52.    )
  53. IF DEFINED SecondDNS (
  54.    set SecondsDNS=netsh int ip add dns "Local Area Connection" %SecondDNS%
  55.    set WifiSecond=netsh int ip add dns "Wireless Network Connection" %SecondDNS%
  56.    set SecondResult=Second DNS Server = %SecondDNS%
  57.    ) else (
  58.    set SecondsDNS=echo Settings DNS without secondary DNS
  59.    set WifiSecond=echo Settings DNS without secondary DNS
  60.    set SecondResult=Second DNS Server = No Second DNS exist
  61.    )
  62. for /f "tokens=1" %%G in ('ipconfig /all ^| find "Wireless LAN"') do @set WifiSet=%%G
  63. if DEFINED WifiSet (
  64.    set WifiOn=1
  65.    ) else (
  66.    set WifiOn=0
  67.    )
  68. goto:settingsdns
  69. exit
  70. :settingsdns
  71. echo.
  72. echo Tweaking Up for Local Area Network..
  73. echo.
  74. netsh int ip set dns "Local Area Connection" static %MainDNS% primary>nul
  75. if %errorlevel%==1 call:error
  76. %SecondsDNS%>nul
  77. if %errorlevel%==1 call:error
  78. if %WifiOn%==1 goto:wifiset
  79. goto:end
  80. exit
  81. :wifiset
  82. echo Wireless Detected! Tweaking Up for Wireless Network..
  83. echo.
  84. netsh int ip set dns "Wireless Network Connection" static %MainDNS% primary>nul
  85. if %errorlevel%==1 call:error
  86. %WifiSecond%>nul
  87. if %errorlevel%==1 call:error
  88. :end
  89. echo Complete Change DNS for your computer..
  90. echo.
  91. echo First DNS Server = %MainDNS%
  92. echo.
  93. echo %SecondResult%
  94. echo.
  95. pause
  96. exit
  97. :error
  98. echo.
  99. echo ---------------------------------------------------------------------
  100. echo Error Was Detected, it seem you must have administrator privilege...
  101. echo ---------------------------------------------------------------------
  102. echo.
  103. pause
  104. exit
  105. goto:eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement