VC++ calls IcmpSendEcho function to realize ping detection of remote address (with source code)

       A friend asked such a question in the comment area of ​​the article before. Is there a way to ping the remote address through code, and judge whether the network of the remote device is faulty based on whether the ping can be successful? The answer is yes, I wrote a small tool for a friend before, which has a function of ping IP address. In fact, it is very simple, it can be achieved by calling the system API function IcmpSendEcho . Today we will briefly talk about this topic and explain some of the details that need attention.

1. Ping the target address in the cmd window

       When we cannot access the remote network address, our first reaction is to open the cmd command window and ping the remote address to see if we can ping it. The address of the remote device can be an IP or a domain name. When the ping command is executed, 3 ping packets are sent to the remote end. According to the response of the remote end, when the network is normal, there will be the following responses:


According to the ping result, you can see whether the network connection is normal, whether the network has a large delay, and whether the network has packet loss.
       We can also add a -t parameter to the back to send ping packets all the time:

Guess you like

Origin blog.csdn.net/chenlycly/article/details/124351391