40 lines
740 B
C
40 lines
740 B
C
|
|
#ifdef _WIN32
|
|||
|
|
#ifndef _PING_
|
|||
|
|
#define _PING_
|
|||
|
|
|
|||
|
|
#include <iostream>
|
|||
|
|
#include <windows.h>
|
|||
|
|
#include <string>
|
|||
|
|
|
|||
|
|
#define DEF_BUF_SIZE 1024
|
|||
|
|
#define ICMP_DATA_SIZE 32
|
|||
|
|
#define IP_HEADER_SIZE 20
|
|||
|
|
#define ICMP_HEADER_SIZE 12
|
|||
|
|
#define ICMP_PACK_SIZE ICMP_HEADER_SIZE+ICMP_DATA_SIZE
|
|||
|
|
|
|||
|
|
typedef struct _ICMP_HEADER
|
|||
|
|
{
|
|||
|
|
BYTE bType;//<2F><><EFBFBD><EFBFBD>
|
|||
|
|
BYTE bCode;//<2F><><EFBFBD><EFBFBD>
|
|||
|
|
USHORT nCheckSum;//У<><D0A3><EFBFBD><EFBFBD>
|
|||
|
|
USHORT nId;//<2F><>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID
|
|||
|
|
USHORT nSequence;//<2F><><EFBFBD>к<EFBFBD>
|
|||
|
|
UINT nTimeStamp;//<2F><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
}ICMP_HEADRE,*PICMP_HEADER;
|
|||
|
|
|
|||
|
|
|
|||
|
|
class CPing
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
//windows ping ip
|
|||
|
|
static int Ping(const std::string& DestIp,const int delayTime = 1000);
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
|
|||
|
|
//Helper function to fill in various stuff in our ICMP request.
|
|||
|
|
static USHORT GetCheckSum(LPBYTE lpBuf,DWORD dwSize);
|
|||
|
|
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
#endif
|
|||
|
|
#endif
|