Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for dhcpscopes.bat

(view source code of dhcpscopes.bat as plain text)

  1. @ECHO OFF
  2. REM Obtains all active DHCP Scopes authorized in the domain
  3. REM Josh Murray V. 6.8.18
  4.  
  5. SETLOCAL ENABLEDELAYEDEXPANSION
  6.  
  7. ECHO dhcp > script2.txt
  8. ECHO set file open dhcp.txt >> script2.txt
  9.  
  10. REM Import DHCP Servers
  11. ECHO dhcp > script1.txt
  12. ECHO set file open temp.txt >> script1.txt
  13. ECHO show server >> script1.txt
  14. ECHO exit >> script1.txt
  15. NETSH -f script1.txt >nul
  16.  
  17. REM Check if servers are reachable
  18. CLS
  19. ECHO Scanning Servers
  20. ECHO Server not responding (If name is Address, there is a blank entry in AD) :> error.log
  21.  
  22. FOR /F "tokens=2 delims=[]" %%A in (temp.txt) DO (
  23. 	PING -n 2 %%A | FIND "TTL=" >NUL
  24. 	IF !ERRORLEVEL! NEQ 0 (
  25. 		ECHO Server unreachable %%A >> error.log
  26. 	) ELSE (
  27. 		ECHO server \\%%A >> script2.txt
  28. 		ECHO show scope >> script2.txt
  29. 	)
  30. ) 
  31.  
  32. ECHO exit >> script2.txt
  33.  
  34. REM Get scopes
  35. CLS
  36. ECHO Enumerating Scopes
  37. NETSH -f script2.txt >NUL
  38.  
  39. REM Cleanup Logs
  40. TYPE dhcp.txt | FIND "Active" > Scopes.txt
  41. ECHO ******************************>> error.log 
  42. ECHO DHCP Service may be disabled: >> error.log 
  43. TYPE dhcp.txt | FIND "Unable to determine" >> error.log
  44.  
  45. DEL temp.txt
  46. DEL script*
  47.  
  48. CLS
  49. ECHO Complete, Check Scopes.txt for DHCP scopes and error.log for failed connections.
  50. ENDLOCAL
  51. PAUSE
  52.  

page last modified: 2024-04-16; loaded in 0.0106 seconds