1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
bool Ping(std::string SiteName)
{
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
addrinfo* AddrInfo = NULL;
addrinfo hints;
memset(&hints, 0, sizeof(addrinfo));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE;
if(getaddrinfo(SiteName.c_str(), "http", &hints, &AddrInfo) != ERROR_SUCCESS)
{
WSACleanup();
return false;
}
sockaddr_in* AddrIn = reinterpret_cast<sockaddr_in*>(AddrInfo->ai_addr);
std::string dotAddress = inet_ntoa(AddrIn->sin_addr);
HANDLE ICMPHandle = IcmpCreateFile();
IPAddr IPAddress = inet_addr(dotAddress.c_str());
bool Return = true;
char Data[100];
sprintf_s(Data, 100, "Data");
unsigned DataBufferSize = sizeof(Data);
DWORD DataSize;
const unsigned EchoArraySize = 25;
ICMP_ECHO_REPLY Echo[EchoArraySize];
DWORD EchoSize = (sizeof(ICMP_ECHO_REPLY) * EchoArraySize);
DWORD EchoResult = IcmpSendEcho(ICMPHandle, IPAddress, Data, DataBufferSize, NULL, Echo, EchoSize, 3000);
if(EchoResult == 0)
{
//std::cout << "Echo Result: " << EchoResult << "\n";
WSACleanup();
Return = false;
}
CloseHandle(ICMPHandle);
WSACleanup();
//std::cout << "Echo Result: " << EchoResult << "\n";
return Return;
}
|