|
@@ -15,6 +15,10 @@
|
|
#include <random>
|
|
#include <random>
|
|
#include <filesystem>
|
|
#include <filesystem>
|
|
#include <any>
|
|
#include <any>
|
|
|
|
+#include <fstream>
|
|
|
|
+#include <string>
|
|
|
|
+#include <vector>
|
|
|
|
+#include <algorithm>
|
|
//openssl
|
|
//openssl
|
|
#include <openssl/des.h>
|
|
#include <openssl/des.h>
|
|
#include <openssl/aes.h>
|
|
#include <openssl/aes.h>
|
|
@@ -40,6 +44,12 @@
|
|
//windows
|
|
//windows
|
|
#ifdef WINDOWS_BUILD
|
|
#ifdef WINDOWS_BUILD
|
|
#include <Windows.h>
|
|
#include <Windows.h>
|
|
|
|
+#include <httpext.h>
|
|
|
|
+#include <windef.h>
|
|
|
|
+#include <Iphlpapi.h>
|
|
|
|
+#pragma comment(lib,"iphlpapi.lib")
|
|
|
|
+#elif LINUX_BUILD
|
|
|
|
+#include <dirent.h>
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#ifdef WINDOWS_BUILD
|
|
#ifdef WINDOWS_BUILD
|
|
@@ -1304,6 +1314,58 @@ namespace robotics {
|
|
std::chrono::time_point<std::chrono::high_resolution_clock> start_;
|
|
std::chrono::time_point<std::chrono::high_resolution_clock> start_;
|
|
std::chrono::time_point<std::chrono::high_resolution_clock> end_;
|
|
std::chrono::time_point<std::chrono::high_resolution_clock> end_;
|
|
};
|
|
};
|
|
|
|
+ /**
|
|
|
|
+ * @brief 获取本机所有网络接口的 MAC 地址列表。
|
|
|
|
+ * @return 一个包含所有唯一 MAC 地址的字符串向量,每个字符串为一个网络接口的 MAC 地址。
|
|
|
|
+ */
|
|
|
|
+ inline std::vector<std::string> mac() {
|
|
|
|
+ std::vector<std::string> result;
|
|
|
|
+#ifdef WINDOWS_BUILD
|
|
|
|
+ PIP_ADAPTER_INFO pAdapterInfo;
|
|
|
|
+ PIP_ADAPTER_INFO pAdapter = NULL;
|
|
|
|
+ DWORD dwRetVal = 0;
|
|
|
|
+ ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
|
|
|
|
+ pAdapterInfo = (IP_ADAPTER_INFO*)HeapAlloc(GetProcessHeap(), 0, sizeof(IP_ADAPTER_INFO));
|
|
|
|
+ if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
|
|
|
|
+ HeapFree(GetProcessHeap(), 0, pAdapterInfo);
|
|
|
|
+ pAdapterInfo = (IP_ADAPTER_INFO*)HeapAlloc(GetProcessHeap(), 0, ulOutBufLen);
|
|
|
|
+ }
|
|
|
|
+ if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
|
|
|
|
+ pAdapter = pAdapterInfo;
|
|
|
|
+ while (pAdapter) {
|
|
|
|
+ char buffer[20];
|
|
|
|
+ sprintf_s(buffer, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", pAdapter->Address[0],
|
|
|
|
+ pAdapter->Address[1], pAdapter->Address[2], pAdapter->Address[3],
|
|
|
|
+ pAdapter->Address[4], pAdapter->Address[5]);
|
|
|
|
+ result.push_back(std::string(buffer));
|
|
|
|
+ pAdapter = pAdapter->Next;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (pAdapterInfo)
|
|
|
|
+ HeapFree(GetProcessHeap(), 0, pAdapterInfo);
|
|
|
|
+#elif LINUX_BUILD
|
|
|
|
+ DIR* dir = opendir("/sys/class/net");
|
|
|
|
+ if (!dir) return result;
|
|
|
|
+ struct dirent* entry;
|
|
|
|
+ while ((entry = readdir(dir))) {
|
|
|
|
+ std::string ifname = entry->d_name;
|
|
|
|
+ if (ifname == "." || ifname == "..") continue;
|
|
|
|
+ std::ifstream addrFile("/sys/class/net/" + ifname + "/address");
|
|
|
|
+ std::string macstr;
|
|
|
|
+ if (std::getline(addrFile, macstr)) {
|
|
|
|
+ if (macstr != "00:00:00:00:00:00") {
|
|
|
|
+ result.push_back(macstr);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ closedir(dir);
|
|
|
|
+#endif
|
|
|
|
+ std::sort(result.begin(), result.end());
|
|
|
|
+ std::vector<std::string>::iterator pos;
|
|
|
|
+ pos = std::unique(result.begin(), result.end());
|
|
|
|
+ result.erase(pos, result.end());
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|