Revision: 13486
Updated Code
at April 25, 2009 20:21 by oktane
Updated Code
@echo off rem Set this to the hostname that you just updated the A record on set hostchk=server.example.org rem Set this to the new A record address set correctip=127.127.127.127 nslookup %hostchk%|| goto errornons rem this is tricky, look for two of the strings "Address" nslookup -type=A %hostchk% 2>nul | find /c "Address" | find "2" > nul if ErrorLevel 1 goto error for /f "tokens=2" %%a in ('nslookup %hostchk%') do set curhostip=%%a cls Echo Your computer thinks %hostchk% goes to %curhostip% if /i "%curhostip%"=="%correctip%" goto allgood goto flush :allgood echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo That's CORRECT, you're all set for the server transition! echo When the server comes online, you'll be ready to go. echo Make sure all your programs reference %hostchk% and not an IP. echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pause exit :error echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Echo For some reason, your computer cannot look up %hostchk%. Echo Put help text here Echo Be sure to tell us this error: can't resolve %hostchk% echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pause exit :errornons echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Echo Your computer doesn't have nslookup so this batch file won't work. echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pause exit :error2 echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Echo For some reason, your computer or ISP still cannot find the right IP Echo Put help text here Echo Be sure to tell us this error: got wrong ip %curhostip% echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pause exit :flush echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo That's INCORRECT, it should be %correctip%, so lets flush the DNS cache echo now and see if it will help. ipconfig /flushdns Echo After you press a key, we'll see if flushing the cache worked. echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pause for /f "tokens=2" %%a in ('nslookup %hostchk%') do set curhostip=%%a cls if /i "%curhostip%"=="%correctip%" goto allgood goto error2
Revision: 13485
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at April 25, 2009 20:08 by oktane
Initial Code
@echo off rem Set this to the hostname that you just updated the A record on set hostchk=server.example.org rem Set this to the new A record address set correctip=127.127.127.127 nslookup %hostchk%|| goto errornons rem this is tricky, look for two of the strings "Address" nslookup -type=A %hostchk% 2>nul | find /c "Address" | find "2" > nul if ErrorLevel 1 goto error for /f "tokens=2" %%a in ('nslookup %hostchk%') do set curhostip=%%a cls Echo Your computer thinks %hostchk% goes to %curhostip% Echo The correct address is actually %correctip% if /i "%curhostip%"=="%correctip%" goto allgood goto flush :allgood echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo That's CORRECT, you're all set for the server transition! echo When the server comes online, you'll be ready to go. echo Make sure all your programs reference %hostchk% and not an IP. echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pause exit :error echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Echo For some reason, your computer cannot look up %hostchk%. Echo Put help text here Echo Be sure to tell us this error: can't resolve %hostchk% echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pause exit :errornons echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Echo Your computer doesn't have nslookup so this batch file won't work. echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pause exit :error2 echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Echo For some reason, your computer or ISP still cannot find the right IP Echo Put help text here Echo Be sure to tell us this number: Error Result was %curhostip% echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pause exit :flush echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo That's INCORRECT, so lets flush the DNS cache now. ipconfig /flushdns Echo After you press a key, we'll see if flushing the cache worked. echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pause for /f "tokens=2" %%a in ('nslookup %hostchk%') do set curhostip=%%a cls if /i "%curhostip%"=="%correctip%" goto allgood goto error2
Initial URL
Initial Description
Initial Title
ipconfig flushdns batch file, for host DNS A changes, help users to resolve new host
Initial Tags
server, windows
Initial Language
DOS Batch