How to save ipconfig and ping to TXT in CMD
Discover how to capture computer network data and save it directly into text files using simple command-line tricks. This approach helps you build automatic logs and troubleshoot connection problems without needing extra software.
Summary
- A single > writes the command output to a file and replaces what was there.
- >> appends and is the right choice for a history.
- ping -n 4 stops after four packets and returns the prompt.
- ipconfig /all stores adapter, DNS and physical address.
- A .bat file repeats the collection without retyping.
Why send the screen to a file
Command Prompt shows ipconfig and ping only while the window stays open. Close it and the diagnosis is gone. Redirection sends that same answer to a .txt you can attach to a ticket or compare tomorrow.
Windows does not open an editor. The command stays the same. Only the destination changes: a file in the folder you are in, instead of the screen.
Step by step
Open Command Prompt, pick the log folder and run one command at a time. Open the txt in Notepad before you close the window.
- Open Command Prompt. To store logs in C:\Logs, create the folder first with mkdir C:\Logs.
- Use one > to create the file from scratch. A second > on the same name deletes the previous capture.
- Run ping -n 4 8.8.8.8 > ping.txt. Four packets finish on their own. ping -t does not: stop it with Ctrl+C.
- Run ipconfig /all > ipconfig.txt to keep address, mask, gateway and DNS.
- For a history, switch > to >> and put the date on the line above with echo %date% %time%.
- Open the txt. If it is empty, the command failed or you are looking in another folder. cd prints the current path.
echo %date% %time% > diagnostic.txt
ipconfig /all >> diagnostic.txt
ping -n 4 8.8.8.8 >> diagnostic.txtCommon mistakes
The file is created in the Prompt's current folder, not on the Desktop, unless you cd there first. To complement this implementation in production environments, see our related technical analyses on How to Use the Tee Command in Linux to Display and Save Output Simultaneously and How to Resolve Local IP Conflicts Using the ipconfig /renew Command.
- > overwrites. To keep every test, use >>.
- Errors sometimes use another channel. 2>&1 joins errors and normal output in the same txt.
- A path with spaces needs quotes: > "%USERPROFILE%\Documents\ping.txt".
- Do not put ping -t in a .bat without a limit. The window never exits.
Conclusion
One > turns the Prompt's answer into a file. ping -n 4 and ipconfig /all already cover the connectivity test and the network card.
When you will collect this again, put the three commands in a .bat and run the file instead of retyping.