Posted By

deanhouseholder on 03/12/14


Tagged

DNS change watch propagation monitor propagate


Versions (?)

Monitor host for DNS change


 / Published in: DOS Batch
 

If you've ever made (or requested) a DNS change and you want to monitor the requested name to see when it becomes active, this script provides an elegant solution. It will flush your local dns cache, attempt to ping the (host/domain)name, and then wait for 5 seconds before trying again.

Usage:

watchdns.bat

watchdns.bat [name]

  1. @echo off
  2. cls
  3. set host=
  4. set IP=
  5.  
  6. IF NOT [%1]==[] (SET host=%1) ELSE (SET /p host=What host would you like to watch for DNS change? )
  7.  
  8. echo Watching for DNS changes for host %host%
  9.  
  10. :Start
  11. set IP=
  12. echo %date:~4,13% %time:~0,8%
  13. ipconfig /flushdns > NUL
  14. echo Flushed DNS Cache. Attempting to reach host...
  15. for /f "tokens=4 delims= " %%a in ('ping -n 1 -w 0 %host% ^| find "statistics"') do set IP=%%a
  16. IF "%IP%"=="" GOTO Fail
  17. echo Current IP for %host% is: %IP:~0,-1%
  18. GOTO Next
  19.  
  20. :Fail
  21. ECHO Could not find a DNS entry for %host%
  22. GOTO Next
  23.  
  24. :Next
  25. echo Wait 5 seconds...
  26. sleep 5
  27. GOTO Start

Report this snippet  

You need to login to post a comment.