Use the stack to ping your computer

Source: Internet
Author: User

The following class solves a common problem: how to ping Another computer on a WIN95 computer using the MSTCP stack. Of course, this class can also be used on NT3.51 and NT4. Obviously, Microsoft is not so stupid, and in the win system there is another separate mechanism to solve this problem, so that the complex win system is more complex. So, we can only use the ICMP DLL to solve this problem ourselves. However, it was disappointing that Microsoft did not solve the problem until Winsock 2.0.

The problem is: give the name of a computer, or the IP address of a computer, how to ping it, and get its response time. So we used the ICMP DLL, and for some socket structures, it was all defined in the CSocket. So, the following class is a CSocket subclass that will have better functionality to solve more problems. But you'll have to get icmpapi.h,icmapi.cpp,icmp.lib and ipexport.h,ipexport.cpp these files, which should be added to your project. These files are available on the Microsoft Developers Network CD, but they are also available on the Microsoft home page and are updated.

There are 4 common functions in the class, as follows:

unsigned long Resolveip (CString StrIP)

unsigned long resolvename (CString strhostname)

CString getip (unsigned long ulip)

DWORD pinghost (unsigned long ulip, int ipingtimeout)

The Resolveip (CString StrIP) function uses a string of IP addresses as a parameter, and the return value is the IP address value.

The ResolveName (CString strhostname) function uses a string of computer names as a parameter, and after DNS or WINS resolution, the return value is the IP address of the ping computer, noting that it uses gethostbyname modularity.

The GetIP (unsigned long ulip) function is an IP address as an argument (note is an IP address), and the return value is a string representing the IP address.

Pinghost (unsigned long ulip, int ipingtimeout) function, the 1th parameter is the IP address (note is the IP address, not the IP address string), the 2nd parameter is the time value, represents the interval time. The function function is to ping a computer, and the return value is the response time of the ping.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.