| 
 | 
 本帖最后由 aeszyl 于 2024-12-28 10:49 编辑  
 
用代码嵌入版本 
 
 
- <火山程序 类型 = "通常" 版本 = 1 />
 
  
- 包 火山.程序 <
 
 -         @视窗.外部头文件 = "<winsock2.h>\r\n<ws2tcpip.h>\r\n<iphlpapi.h>\r\n<iostream>\r\n<string>\r\n<windows.h>\r\n<cstdlib>\r\n<locale>\r\n<codecvt>"
 
 -         @视窗.外部库 = "Ws2_32.lib\r\nIphlpapi.lib" @视窗.附加编译参数 = "cpp: /std:c++17">
 
  
- 类 嵌入文本 <公开 @强制输出 = 真>
 
 - {
 
  
-     # @begin
 
 -     # std::string getLocalIPAddress() {
 
 -     #     WSADATA wsaData;
 
 -     #     if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
 
 -     #         throw std::runtime_error("WSAStartup failed");
 
 -     #     }
 
 -     #     ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
 
 -     #     ULONG outBufLen = 0;
 
 -     #     PIP_ADAPTER_ADDRESSES pAdapterAddrs = nullptr;
 
 -     #     ULONG retval = GetAdaptersAddresses(AF_UNSPEC, flags, nullptr, pAdapterAddrs, &outBufLen);
 
 -     #     if (retval == ERROR_BUFFER_OVERFLOW) {
 
 -     #         pAdapterAddrs = (PIP_ADAPTER_ADDRESSES)malloc(outBufLen);
 
 -     #         if (pAdapterAddrs == nullptr) {
 
 -     #             WSACleanup();
 
 -     #             throw std::bad_alloc();
 
 -     #         }
 
 -     #         retval = GetAdaptersAddresses(AF_UNSPEC, flags, nullptr, pAdapterAddrs, &outBufLen);
 
 -     #     }
 
 -     #     if (retval != NO_ERROR) {
 
 -     #         if (pAdapterAddrs != nullptr) {
 
 -     #             free(pAdapterAddrs);
 
 -     #         }
 
 -     #         WSACleanup();
 
 -     #         throw std::runtime_error("GetAdaptersAddresses failed");
 
 -     #     }
 
 -     #     std::wstring ipAddressW;
 
 -     #     for (PIP_ADAPTER_ADDRESSES pAdapterAddr = pAdapterAddrs; pAdapterAddr != nullptr; pAdapterAddr = pAdapterAddr->Next) {
 
 -     #         for (PIP_ADAPTER_UNICAST_ADDRESS pUnicastAddr = pAdapterAddr->FirstUnicastAddress; pUnicastAddr != nullptr; pUnicastAddr = pUnicastAddr->Next) {
 
 -     #             sockaddr_in* pSockaddrIn = reinterpret_cast<sockaddr_in*>(pUnicastAddr->Address.lpSockaddr);
 
 -     #             if (pSockaddrIn->sin_family == AF_INET) {
 
 -     #                 wchar_t ac[INET_ADDRSTRLEN];
 
 -     #                 DWORD dwAddressLength = sizeof(ac) / sizeof(wchar_t);
 
 -     #                 if (WSAAddressToString(reinterpret_cast<LPSOCKADDR>(pSockaddrIn), sizeof(sockaddr_in), nullptr, ac, &dwAddressLength) == 0) {
 
 -     #                     ipAddressW = ac;
 
 -     #                     break;
 
 -     #                 }
 
 -     #             }
 
 -     #         }
 
 -     #         if (!ipAddressW.empty()) {
 
 -     #             break;
 
 -     #         }
 
 -     #     }
 
 -     #     if (pAdapterAddrs != nullptr) {
 
 -     #         free(pAdapterAddrs);
 
 -     #     }
 
 -     #     WSACleanup();
 
 -     #     std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
 
 -     #     std::string ipAddress = converter.to_bytes(ipAddressW);
 
 -     #     return ipAddress;}
 
 -     # @end
 
 - }
 
  
- 类 启动类 <公开 基础类 = 程序类>
 
 - {
 
 -     方法 启动方法 <公开 类型 = 整数 @禁止流程检查 = 真>
 
 -     {
 
 -         @ MessageBox(nullptr, reinterpret_cast<LPCWSTR>(std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>().from_bytes(getLocalIPAddress()).c_str()), L"本机IP地址:", MB_OK | MB_ICONINFORMATION);return 0;
 
 -         返回 (1)
 
 -     }
 
 - }
 
 
  复制代码 
 
 
 |   
 
 
 
 |