26 std::string ipAddress =
"";
28 std::string command =
"powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"" + scriptPath.string() +
"\"";
30 FILE* pipe = _popen(command.c_str(),
"r");
33 std::cerr <<
"Erro: Falha ao executar o script PowerShell. Comando: " << command << std::endl;
37 std::array<char, 256> buffer;
40 if (fgets(buffer.data(), buffer.size(), pipe) !=
nullptr)
43 line.erase(0, line.find_first_not_of(
" \t\r\n"));
44 line.erase(line.find_last_not_of(
" \t\r\n") + 1);
49 std::regex ipv4_format_regex(
"^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$");
50 if (!std::regex_match(ipAddress, ipv4_format_regex))
52 std::cerr <<
"Aviso: O script PowerShell retornou algo que não parece um IPv4 válido ou nada: '" << ipAddress <<
"'" << std::endl;
127 int slength = (int)s.length() + 1;
128 len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
129 std::vector<wchar_t> buf(len);
130 MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, &buf[0], len);
131 return std::wstring(&buf[0]);