export async function runKillProcessTest(agent: AgentList): Promise<void> { const…
- User
export async function runKillProcessTest(agent: AgentList): Promise { const checkPing = async (cmd: string): Promise => { try { return (await sshService.execCommandKey(agent, [{ cmd }]))[0].stdout; } catch (e) { return ''; } }; const windowsPlatform = agent.os.platform === Platform.Windows; const pingAll = windowsPlatform ?
tasklist | findstr /I ${Cmd.Ping}:ps -A | grep ${Cmd.Ping}; const killPingProcesses = windowsPlatform ?taskkill /F /IM ${Cmd.Ping}:pkill ${Cmd.Ping}; const takePID = windowsPlatform ?(Get-Process -Name ${Cmd.Ping}).Id:pidof ${Cmd.Ping};console.log('до pkill', await checkPing(pingAll)); if (await checkPing(pingAll)) { await checkPing(killPingProcesses); console.log('после pkill', await checkPing(pingAll)); }
if (windowsPlatform) { void checkPing(
'Start-Process ${Cmd.Ping} -ArgumentList -t 8.8.8.8 -WindowStyle Hidden'); } else { void sshService.execCommandKey(agent, [{ cmd:${Cmd.Ping} 8.8.8.8 &}]); }await OperationRepeater.RepeatUntil(async () => (await checkPing(pingAll)).length > 0); console.log('после добавления ping', await checkPing(pingAll)); // const pid = parseInt((await checkPing(pingAll)).trim().slice(0, 9), 10).toString(); const pid = await checkPing(takePID); await OperationRepeater.RepeatUntil(async () => (await checkPing(pingAll)).includes(pid)); console.log('наш pid ===', pid); console.log('наш ping после того, как получили pid ===', await checkPing(pingAll)); expect(Number(pid), 'ping is not added').toBeGreaterThan(1); expect((await checkPing(pingAll)).includes(pid)).toBeTruthy();
console.log(pid);
const activeResponse = await activeResponseService.setCommand(agent.id, ActiveResponseCommand.KillProcess, { pid, });
expect(activeResponse.error, 'error active response').toEqual(0);
console.log('после kill запроса', await checkPing(pingAll));
await OperationRepeater.RepeatUntil(async () => (await checkPing(pingAll)).includes(pid) === false, 10);
expect((await checkPing(pingAll)).includes(pid),
pid:${pid} process is not killed).toBeFalsy(); }почему-то команда на добалвение ip не работает в windows
- Assistant
Возможно, проблема заключается в неправильном синтаксисе команды для Windows. Попробуйте изменить следующую строку:
void checkPing(`'Start-Process ${Cmd.Ping} -ArgumentList -t 8.8.8.8 -WindowStyle Hidden'`);на
void checkPing(`Start-Process ${Cmd.Ping} -ArgumentList "-t", "8.8.8.8", "-WindowStyle", "Hidden"`);Это должно правильно передавать аргументы команды
Pingв Windows.