Solved

write Ipconfig commands with a batch file

Posted on 2009-07-13
13
1,693 Views
Last Modified: 2013-11-09

write Ipconfig command with a batch file

I need to write a batch file that runs the following commands and puts the results in C:\Result.txt file

Ipcongig /Flushdns
Ipconfig /release
Ipconfig /renew
Ipconfig /Registerdns

Thanks
0
Comment
Question by:jskfan
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 8

Expert Comment

by:NotLogical
Comment Utility
Hi,

The easiest way to do this is as follows. Start notepad, and copy the following text into it:

@echo off
echo. >> c:\Result.txt
ipconfig /flushdns >> c:\Result.txt
ipconfig /release >> c:\Result.txt
ipconfig /renew >> c:\Result.txt
ipconfig /Registerdns >> c:\Result.txt

Save this as (for example) c:\Show_Ipconfig.cmd, and you are ready to go!

This script will continually append to the c:\Result.txt file. If you want to create a new file everytime this script is run, change the second line to read "echo. > c:\Result.txt". Please note that there is no space between the echo and the "."!

Cheers,

NotLogical
0
 

Author Comment

by:jskfan
Comment Utility
it pops up black screen (CMD window)
it stays on that windows forever
it creates 2 text files (Result) one with 0 bytes and one with incrementing bytes if I stop the script from running and go to the Result files there is nothing inside.
0
 
LVL 8

Expert Comment

by:NotLogical
Comment Utility
Hi,

I just tried this under Windows XP, without trouble. Did you copy and paste the script directly from the text above?

Please keep in mind the following: the script will appear to "hang" if any of the commands take long to execute. So, if the DHCP release/renew take 45 seconds (due to a problem with the DHCP server), the entire script will have just a window showing and nothing will seem to happen.

Just in case, I have attached it with this comment. Please rename it from a ".txt" to a ".cmd" before using. The modified script will also show you textual progress of what it is doing. Thus, you will know which step is slow...

Cheers,

NotLogical

Show-Ipconfig.txt
0
 

Author Comment

by:jskfan
Comment Utility
to make it simple.
Can you run the Ipconfig /all and put the result in Result.txt?
0
 
LVL 8

Expert Comment

by:NotLogical
Comment Utility
Sure!

Simply take the script as indicated previously, and remove all but one of the ipconfig lines. Then, change the "/" option to be "/all" instead of whatever was there previously.

If you want to wipe out the contents of the Result.txt file between every run, change the ">>" to a single ">" in the second line of the script.

NotLogical
@echo off

echo. >> c:\Result.txt

echo Getting IP information...

ipconfig /all >> c:\Result.txt

echo IP information retrieved.

Open in new window

0
 

Author Comment

by:jskfan
Comment Utility
do you know why it takes too long through a batch file.
if you run it in a command line: ipconfig /all it displays the config in a second.
0
Want to promote your upcoming event?

Attending an event? Speaking at a conference? Or exhibiting at a tradeshow? Easily inform your contacts by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

 
LVL 3

Assisted Solution

by:cclassen
cclassen earned 150 total points
Comment Utility
How are you launching the batch file, and where are you running it from?
is it possible it is not running under an appropriate security context for the commands?

If you are launching one batch file from another, it may be trying to run under 'system' context, which won't have the appropriate rights.

Can you post your file(s) here for review?  
0
 
LVL 8

Expert Comment

by:NotLogical
Comment Utility
Hi again,

Could you explain what you mean by "too long?" Do you mean a 1/2 second, or several seconds? Can you post the output of Result.txt? Could you give a little more information about your setup?

There are several things which can affect CMD script execution -  but these are beyond the scope of your original question.

Cheers,

NotLogical
0
 
LVL 1

Assisted Solution

by:alex_vj
alex_vj earned 150 total points
Comment Utility
Hey jskfan,

Try the following in a batch file and lemme know if it works for you.

set Logfile=C:\result.txt
@echo RENEW DNS/IP BATCH > "%Logfile%"
@echo ================== >> "%Logfile%"
ipconfig /flushdns >> "%Logfile%"2>&1
ipconfig /release >> "%Logfile%"2>&1
ipconfig /renew >> "%Logfile%"2>&1
ipconfig /registerdns >> "%Logfile%"2>&1

@echo RENEW DNS/IP BATCH HAS ENDED...
@echo REVIEW C:\result.txt FOR DETAILS. CLOSE TO EXIT !
@pause>nul
0
 
LVL 1

Expert Comment

by:alex_vj
Comment Utility
Hey jskfan,

Also remember that the above batch script will need to be run as an administrator to give it the relevant permissions to execute the script. Right click the batch file and choose the Run As option if needed.
0
 

Author Comment

by:jskfan
Comment Utility
how do you run this batch file against remote computers
0
 
LVL 8

Accepted Solution

by:
NotLogical earned 200 total points
Comment Utility
0
 

Author Comment

by:jskfan
Comment Utility
I have PStools.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The use of stolen credentials is a hot commodity this year allowing threat actors to move laterally within the network in order to avoid breach detection.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now