Reset Network Batch Script

Appletax

Well-Known Member
Reaction score
396
Location
Northern Michigan
ipconfig /release
ipconfig /renew
ipconfig /flushdns
ipconfig /registerdns


^ copy and paste into notepad. Save as Reset Network.bat

the .bat extension will save the file as a batch file to automatically
run the commands show above.



This releases the IP address and gets a new one
Flushes out the DNS cache, which maps IP addresses to web site addresses (resolves names to addresses)
(will flush out bad DNS entries if present)
ipconfig /registerdns



ipconfig /displaydns shows the DNS resolver cache
 
Last edited:
Sometimes the release and renew commands take a bit to fully run... would there be an issue with this script trying to run the 4 commands so quickly?
 
Sometimes the release and renew commands take a bit to fully run... would there be an issue with this script trying to run the 4 commands so quickly?

I have no idea. Does the batch wait for one command to finish
before executing the next?


Edit: I just executed the batch file and it did one command and waited for it to finish
before executing the next command
 
With batch commands, the next line in the command will execute after it receives a return code from the previous command. Most commands won't return until they complete and the process is terminated. The ipconfig command is a perfect example of that. So is ping, copy, etc. There are commands that will return a code immediately, even if the process hasn't completed. Keep in mind that a command is nothing more than a executable program that may or may not, accept arguments. Notepad for example, is a command. Open up a command prompt and type in

notepad abc.txt

Notepad will open up and, assuming no abc.txt exists in the current directory, ask you to create a new text file called abc.txt. If you look at the command line, you'll notice that the next line has appeared and you are able to type a new command in. But Wait, but notepad is still open and running? That's because notepad returned a 0 error code (despite that verbiage, a 0 error code means there was no error. For that reason, it's often referred to as a 'return code') after the program successfully launched, rather than wait until it was closed. But what if I want to wait until it closes? Like I want to show the user a log file, and when they close it, resume my commands? You're in luck, Windows provides, yet another command to handle that. Rather than typing in notepad, type this in to the command line:

start /wait notepad.exe abc.txt

You'll notice that the command line pauses while notepad.exe is open. Once it closes, the command line will resume and you will be able to type in a new command. Using the start command with the /wait argument tells Windows: I want you to start this program, but I want you to wait until the process closes, rather than waiting until a return code is received, to continue.

Typically, the the 32-bit GUI programs are what will return an error code after the program launched, and not when it's closed. Notepad is a good example of this.
 
Last edited:
try it this way in a .bat

@echo off
cls
@ipconfig /release *CON*
@ipconfig /flushdns
@ipconfig /renew
@ipconfig /registerdns

exit
The cls is unnecessary unless you are planning on running the batch from a command line. If you are doing that, the exit will cause the windows to close, otherwise, it's unnecessary.

For those who don't know the difference, all those @ symbols means that the resulting stdout (Output text) will not be displayed, so the screen will sit there with a blank screen and a blinking cursor until it finishes.
 
Last edited:
When I need to flush the cache and renew IP leases I tend to throw in an NBTSTAT -R and NBTSTAT -RR also just for good measure.
(The -R and -RR have to be in caps.)
 
With batch commands, the next line in the command will execute after it receives a return code from the previous command. Most commands won't return until they complete and the process is terminated. The ipconfig command is a perfect example of that. So is ping, copy, etc. There are commands that will return a code immediately, even if the process hasn't completed. Keep in mind that a command is nothing more than a executable program that may or may not, accept arguments. Notepad for example, is a command. Open up a command prompt and type in

notepad abc.txt

Notepad will open up and, assuming no abc.txt exists in the current directory, ask you to create a new text file called abc.txt. If you look at the command line, you'll notice that the next line has appeared and you are able to type a new command in. But Wait, but notepad is still open and running? That's because notepad returned a 0 error code (despite that verbiage, a 0 error code means there was no error. For that reason, it's often referred to as a 'return code') after the program successfully launched, rather than wait until it was closed. But what if I want to wait until it closes? Like I want to show the user a log file, and when they close it, resume my commands? You're in luck, Windows provides, yet another command to handle that. Rather than typing in notepad, type this in to the command line:

start /wait notepad.exe abc.txt

You'll notice that the command line pauses while notepad.exe is open. Once it closes, the command line will resume and you will be able to type in a new command. Using the start command with the /wait argument tells Windows: I want you to start this program, but I want you to wait until the process closes, rather than waiting until a return code is received, to continue.

Typically, the the 32-bit GUI programs are what will return an error code after the program launched, and not when it's closed. Notepad is a good example of this.

Linux works in the reverse of this.

If you type kwrite in the console it will open kwrite and hold the console window until kwrite closes. it will also kill kwrite if you close the console window.
 
Linux works in the reverse of this.

If you type kwrite in the console it will open kwrite and hold the console window until kwrite closes. it will also kill kwrite if you close the console window.

I have never used kwrite, I use VIM nano and those type, but you can make the bash script run in the back ground. I do that often, my server is all CLI and I use ssh, so I use this instead of opening a new tty.
 
Back
Top