-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWNetHelper.h
72 lines (52 loc) · 1.84 KB
/
WNetHelper.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef WUTILS_NETHELPER_H
#define WUTILS_NETHELPER_H
#include <string>
#include <vector>
#include <winsock2.h>
#include <iphlpapi.h>
#ifdef __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C
#endif // __cplusplus
#ifdef WBASE_EXPORTS
#define WNETHELPER_API __declspec(dllexport)
#else
#define WNETHELPER_API __declspec(dllimport)
#endif // WBASE_EXPORTS
#define G_WNetHelper WNetHelper::getInstance()
class WNetHelper
{
public:
~WNetHelper();
static WNetHelper& getInstance();
const char* GetCode(int length = 6, bool refresh = false);
const char* GetCodeEx();
const char* GetIP();
std::string IPToCode(int length, const char* ip, bool refresh = false);
std::string IPToCodeEx(const char* ip);
const char* CodeToIP(const char* code);
const char* CurrentLocalCode();
bool BonjourServiceIsRunning();
bool IsFirewallRuleEnabled();
bool IsValidIP(const char* ip);
bool IsLocalIP(const char* ip); //主要针对多网卡情况
private:
WNetHelper();
void QueryAdapterList();
void CleanAdapterList();
std::vector<IP_ADAPTER_ADDRESSES>& GetAdapterList();
IP_ADAPTER_ADDRESSES GetFirstConnectedAdapter();
//获取一个有效的IP地址,如果存在多个网卡,取其中一个,且不保证固定
std::string IPSegmentAddress(int segments);
std::string GetIpStr(const struct sockaddr* sa);
std::string GetCurrentIPAddress();
std::string GetCurrentDefaultGateway(IP_ADAPTER_ADDRESSES adapter);
std::string m_curCode;
std::string m_curIP;
std::vector<IP_ADAPTER_ADDRESSES> m_adapters;
std::vector<uint8_t> m_adapterAddresses;
std::string m_ruleName; // firewall rule name, same as LetsView
std::string m_fullProgramPath; // full path to the executable, same as C:\\Path\\to\\LetsView.exe
};
#endif // WUTILS_NETHELPER_H