October 13, 2023
Original articles must be credited
In many cases, easiest way to check if a digital device is connected is to ping. What if there are 10, 100 or 1000 devices? Everyone who pings in past will be stupid.
Recently, I was working on a digital video intercom project and ran into a lot of problems in determining IP addresses. Here I will introduce you to a quick and easy trick.
Look at code first, directly type "for /L %D in (1,1,255) do ping -n 1 192.168.1.%D" in command prompt window, do not enter quotes, as shown in figure below, change segment of IP address to your own. Range of IP addresses to check. Try this is not very convenient and fast.
But code above looks very problematic when a large number is displayed in command prompt window, so let's update it again and use following code.
for /L %D at (1,1,255) do ping -n 1 192.168.1.%D >>a.txt
This will import results into a .txt file. After completing all IP address checks, open .txt file and look for "TTL=" that contains it, i.e. address. As shown below
Many people want to say this and look for it, which is not very convenient. It's okay, I'll update code again.
for /l %D at (1,1,255) do (ping 192.168.1.%D -n 1 && echo 192.168.1.%D>>ok.txt || echo 192.168.1.%D >> №.txt)
This code will put pinged IP address and unreachable IP address into two files, isn't it very convenient? As shown below
Someone again wants to tell me what to do if ping IP address is another network segment IP address or a non-standard IP address, I will help you solve this problem.
for /f %D in (ip.txt) do (ping %D -n 1 && echo %i>>ok.txt || echo %D >>no.txt)< /p>
When you see that ip.txt file is no more, you need to prepare this file yourself, write your ping address to this file, code will read ip address in this file, and upload result to Go inside two files. I will not give here a screenshot that looks like picture above.
Note that files generated by code above are in default directory of your command line, i.e. if your command line status is "c:\windows\system32>" then generated files are in system32 directory. If it is "c:\" then file is located in root directory of C drive. This can be adjusted according to your actual situation.
Is this little trick really handy? You can also directly save code as a .bat and run it directly on a Windows system.
Welcome to our Toutiao account, WeChat official account, Sina Weibo account, Penguin account, QQ official account, UC subscription account, Yidian information, Baidu Baijia account, if you search "weak current intellectual network" to corresponding application, you can follow us. You can also visit our official website www.ruodian360.com