Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
3
Indexable
Never
string GetMAC()
{
    string TempPath = getenv("TEMP");
    string MACFile = TempPath + "\\MAC.bat";
    ofstream WriteScript(MACFile, std::ofstream::trunc);
    WriteScript << XorStr("powershell get-NetAdapter >> %temp%\\MAC.zb");
    WriteScript.close();
    string Code = "cmd.exe /c \"" + MACFile + "\"";
    wstring wCode;
    wCode.assign(Code.begin(), Code.end());
    LPWSTR LPWSTRCode = const_cast<wchar_t*>(wCode.c_str());
    STARTUPINFO si;
    ZeroMemory(&si, sizeof(STARTUPINFO));
    si.cb = sizeof(si);
    PROCESS_INFORMATION pi;
    ZeroMemory(&pi, sizeof(pi));
    bool Debug = CreateProcess(NULL, LPWSTRCode, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
    WaitForSingleObject(pi.hProcess, INFINITE);
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
    string Results = TempPath + "\\MAC.zb";
    ifstream ReadResult(Results);
    string PotentialMAC;
    string AllMacs = "";
    while (getline(ReadResult, PotentialMAC))
    {
        if (!(PotentialMAC == "" || PotentialMAC.substr(0, 4) == "Name" || PotentialMAC.substr(0, 4) == "----"))
        {
            try
            { // 87 
                string MAC = PotentialMAC.substr(87);
                MAC = MAC.substr(0, 17);
                AllMacs += MAC + " | ";
            }
            catch (...) {}
        }
    }
    ReadResult.close();
    remove(MACFile.c_str());
    remove(Results.c_str());
    return AllMacs.substr(0, AllMacs.length() - 3);
}