Batch script to clear Dns Cache/ Clear Clutter

Discussion in 'Scripting' started by MrRTM, Nov 28, 2022.

  1. MrRTM

    MrRTM MDL Member

    Aug 27, 2013
    124
    12
    10
    Hi All,

    I just made a small batch file that clears all the DNS cache and also clear windows update temp files:
    If theres anything more we can add to it please let me know. Instead of typing one by one command its easier. I know there are apps like ccleaner etc but I think this is better.

    ipconfig /flushdns
    nbtstat -R
    nbtstat -RR
    netsh int reset all
    netsh int ip reset
    netsh winsock reset
    ipconfig /flushdns
    nbtstat -R
    nbtstat -RR
    netsh int reset all
    netsh int ipv4 reset
    netsh int ipv6 reset
    netsh winsock reset
    Dism.exe /online /Cleanup-Image /StartComponentCleanup
    Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
    Dism.exe /online /Cleanup-Image /SPSuperseded
    net stop wuauserv
    CD %Windir%
    CD SoftwareDistribution
    DEL /F /S /Q Download
    net start wuauserv
     
  2. sml156

    sml156 MDL Member

    Sep 8, 2009
    196
    115
    10
    Not sure why you would wand to delete DNS cache, Windows and probably every OS out there that follow RFC rule's will delete domains from the cache when their TTL expires.

    TTL's are typically measured in seconds, So a TTL of 300 is 300 seconds and windows will delete any domain with this ttl on it's own with no help from you.

    Windows will by default delete domains from the cache after 24 hours
    Windows will also delete the cache when you reboot or turn off your computer.

    You can test this yourself by looking at the DNS cache.

    Visit a site that you do not frequent very often for example:
    www.social-engineer.org

    Then use this command
    Code:
    ipconfig /displaydns
    You should be able to find the domain in the output.

    Now wait 2 or 3 minutes and run the command again, like magic it's gone. If it's not gone your doing something wrong.

    Edit: When I was writing this post the total number of domains returned was 71, My computer has been running for 22 hours and I can grantee you that I have visited way more that that.

    I usually use the clip command to make it easier to copy the output to the clipboard and the paste it into notepad.

    Code:
    ipconfig /displaydns | clip
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...