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;//类型
|
|
BYTE bCode;//代码
|
|
USHORT nCheckSum;//校验和
|
|
USHORT nId;//标识本进程ID
|
|
USHORT nSequence;//序列号
|
|
UINT nTimeStamp;//用于计算时间
|
|
}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 |