-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddon.cc
More file actions
34 lines (31 loc) · 1.1 KB
/
addon.cc
File metadata and controls
34 lines (31 loc) · 1.1 KB
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
#include <napi.h>
#include <windows.h>
#include <stdio.h>
#include <netlistmgr.h>
#pragma comment(lib, "ole32.lib" )
#include <chrono>
#include <thread>
#include <iostream>
Napi::Boolean GetConnectivity(const Napi::CallbackInfo & info) {
Napi::Env env = info.Env();
CoInitialize(NULL);
bool inetconnection = false;
INetworkListManager *networkListManager = NULL;
HRESULT hr = CoCreateInstance(CLSID_NetworkListManager, NULL, CLSCTX_ALL, IID_INetworkListManager, (LPVOID *)&networkListManager);
if (SUCCEEDED(hr))
{
NLM_CONNECTIVITY result;
hr = networkListManager->GetConnectivity(&result);
if (SUCCEEDED(hr))
{
if (result & (NLM_CONNECTIVITY_IPV4_INTERNET | NLM_CONNECTIVITY_IPV6_INTERNET)) inetconnection = true;
};
networkListManager->Release();
};
return Napi::Boolean::New(env, inetconnection);
};
Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports.Set(Napi::String::New(env, "GetConnectivity"), Napi::Function::New(env, GetConnectivity));
return exports;
};
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init);