How do I use it?
The CPing::Ping() Member Function
Important things to remember
Little Q 'n' A
ping www.codeguru.comThis command lets you know weather or not that host is up and running. This code gives you that functionality form inside your program. I found a couple of other PING or ICMP articles on codeguru.com, but I failed to get any of them to work under '95. Finding a solution that worked for both 'NT and '95 was hard. After I found it, I figured I'd share it; so I packaged it up into my CPing class.
BOOL Ping( char* strHost );
Return Value
Nonzero if the host specified by strHost responds; otherwise 0.
Parameters
strHost A pointer to the null-terminated name or IP Address of the host to ping. If strHost points to an IP Address, it must be in the "XXX.XXX.XXX.XXX" format.
Remarks
If the host name specified by strHost cannot be resolved, the function returns 0. A return value of 0 can also mean the host failed to respond.
Example
The following example demonstrates the use of CPing::Ping.
// example for CPing::Ping CPing ping; //ping the gateway BOOL bResult = ping.Ping("192.168.0.254"); if( bResult ) { //the gateway is working fine //lets ping a couple of sites to see if we can get out. if(ping.Ping("www.codeguru.com") || ping.Ping("www.netscape.com")) { //works just fine AfxMessageBox("Everything is A OK."); } else { //DNS error or we can't get out. AfxMessageBox("Can't ping outside the subnet. It may be a DNS problem or the ISP's fault."); } } else { //the gateway must be down AfxMessageBox("The gateway or router is down."); }