@@ -2094,3 +2094,84 @@ BOOL firmware_ACPI_WAET()
20942094 }
20952095 return result;
20962096}
2097+
2098+ /*
2099+ Check if machine is hosted on Cloud.
2100+ */
2101+
2102+ BOOL hosting_check ()
2103+ {
2104+ TCHAR msg[256 ] = _T (" Checking if Machine is hosted on Cloud" );
2105+ WSADATA wsaData;
2106+ SOCKET sock = INVALID_SOCKET;
2107+ addrinfo* result = nullptr ;
2108+ addrinfo hints;
2109+ BOOL retVal = FALSE ;
2110+ std::string request;
2111+ std::string response;
2112+ const int bufferSize = 512 ;
2113+ char buffer[bufferSize];
2114+ int bytesReceived = 0 ;
2115+
2116+ if (WSAStartup (MAKEWORD (2 , 2 ), &wsaData) != 0 )
2117+ {
2118+ goto cleanup;
2119+ }
2120+
2121+ sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
2122+ if (sock == INVALID_SOCKET)
2123+ {
2124+ goto cleanup;
2125+ }
2126+
2127+
2128+ memset (&hints, 0 , sizeof (hints));
2129+ hints.ai_family = AF_INET;
2130+ hints.ai_socktype = SOCK_STREAM;
2131+ hints.ai_protocol = IPPROTO_TCP;
2132+
2133+ if (getaddrinfo (" ip-api.com" , " 80" , &hints, &result) != 0 )
2134+ {
2135+ goto cleanup;
2136+ }
2137+
2138+ if (connect (sock, result->ai_addr , static_cast <int >(result->ai_addrlen )) == SOCKET_ERROR)
2139+ {
2140+ goto cleanup;
2141+ }
2142+
2143+ request = " GET /json/?fields=hosting HTTP/1.1\r\n " ;
2144+ request += " Host: ip-api.com\r\n " ;
2145+ request += " Connection: close\r\n\r\n " ;
2146+
2147+ if (send (sock, request.c_str (), static_cast <int >(request.length ()), 0 ) == SOCKET_ERROR)
2148+ {
2149+ goto cleanup;
2150+ }
2151+
2152+ do
2153+ {
2154+ bytesReceived = recv (sock, buffer, bufferSize - 1 , 0 );
2155+ if (bytesReceived > 0 )
2156+ {
2157+ buffer[bytesReceived] = ' \0 ' ;
2158+ response += buffer;
2159+ }
2160+ } while (bytesReceived > 0 );
2161+
2162+ if (bytesReceived == SOCKET_ERROR)
2163+ {
2164+ goto cleanup;
2165+ }
2166+
2167+ if (response.find (" \" hosting\" :true" ) != std::string::npos)
2168+ {
2169+ retVal = TRUE ;
2170+ }
2171+
2172+ cleanup:
2173+ if (result) freeaddrinfo (result);
2174+ if (sock != INVALID_SOCKET) closesocket (sock);
2175+ WSACleanup ();
2176+ return retVal;
2177+ }
0 commit comments