Hey! Everyone!
When it comes to the ping command, network engineers are definitely no strangers to it — every day when troubleshooting network faults, checking for timeouts, and testing latency, we all rely on it for help. But if you have to check 100 or even 1,000 devices, you can’t possibly type the ping command one by one, right? You’d wear out your hands.
Today, let’s talk about batch ping techniques. Whether it’s for the same network segment or cross-network segments, a few tricks will get the job done, and efficiency will be directly maximized.
Reading benefit for today’s article: *"HUAWEI Common Command Collection"* Scan the QR code to add the assistant, reply with the code "Common Commands", and you can get it.
Batch ping in the same network segment, done with one line of command
If you want to check all IPs in a network segment (for example, from 192.168.18.1 to 192.168.18.255), there’s no need to test them one by one. Just type this in the command line:
for /L %D in (1,1,255) do ping 192.168.18.%D
The meaning of this command is simple: from 1 to 255, send ping packets to each IP one by one. %D will automatically be replaced with 1, 2... 255 until the entire network segment is scanned.
The screen will display the ping results of each IP in real-time. You can tell at a glance which ones are reachable and which are not.
Too many results to see clearly? Export to a file for later viewing
If there are too many IPs in the network segment, the command line window will scroll too fast, and you won’t be able to remember which ones are reachable. Don’t worry, upgrade the command to export the results to a text file:
for /L %D in (1,1,255) do ping -n 1 192.168.18.%D >> a.txt
Here, `-n 1` means each IP is pinged only once to save time; `>> a.txt` saves all results to the a.txt file.
After it finishes running, open a.txt and search directly for "TTL=". Those containing this string are the IPs that can be pinged; those not found are unreachable. Isn’t troubleshooting much cleaner this way?
Upgrade again! Automatically separate reachable and unreachable IPs
Still find searching back and forth troublesome? Let the command categorize for you. Try this:
for /l %D in (1,1,255) do (ping 192.168.1.%D -n 1 && echo 192.168.1.%D >> ok.txt || echo 192.168.1.%D >> no.txt)
It will automatically write reachable IPs to ok.txt and unreachable ones to no.txt. After that, just open the two files, and you’ll see reachable and unreachable IPs at a glance, even saving the trouble of filtering.
No need to remember the command. Save this article, copy and paste it next time you use it, and just change the IP segment. It’s worry-free and effortless.
Ultimate trick: Batch ping across network segments, rely on this
If you need to detect IPs from multiple different network segments (for example, both 192.168.1.x and 10.0.0.x), the above methods won’t be enough. At this time, you can use the "IP list" method:
Create a txt file yourself (named ip.txt, for example) and list all the IP addresses to be detected, one per line. Type this in the command line:
/f %D in (ip.txt) do (ping %D -n 1 && echo %D >> ok.txt || echo %D >> no.txt)
The command will automatically read all addresses in ip.txt, ping them one by one, and then split the results into ok.txt and no.txt as usual. No matter how many network segments there are, it’s done in one go.
By the way, the generated files will be stored in the current directory of the command line (for example, if the command line shows "C:\", the files will be in the root directory of the C drive). If you can’t find them, check the path!
These are all the batch ping techniques. The core is to use the loop function of the command line, leaving repetitive operations to the computer, and we just need to check the results. Next time you encounter a large number of devices to troubleshoot, try these tricks — the efficiency will definitely be different.
For more Common Commands resources, follow the Facebook account & youtube account: Thinkmo Dumps