Почти не клиент но думаю сгодитсяnubik написал(а):нужен ssh клиент рабочий
::Administrator Right
cd /d "%~dp0"
Powershell -C "Set-ExecutionPolicy Unrestricted; if (-not (Get-Module -Name Posh-SSH -ErrorAction SilentlyContinue)) { Install-Module -Name Posh-SSH -Force -AllowClobber -Scope CurrentUser }; Install-Module Posh-SSH -Force -SkipPublisherCheck; Import-Module Posh-SSH; $password = ConvertTo-SecureString '12345' -AsPlainText -Force; $sessionssh = New-Object System.Management.Automation.PSCredential ('Home', $passwors); $sshSession = New-SSHSession -ComputerName '192.168.100.5' -Credential $sessionssh; $commandResult = Invoke-SSHCommand -SSHSession $sshSession -Command 'ipconfig'; Write-Output $commandResult.Output; Remove-SSHSession -SSHSession $sshSession; Set-ExecutionPolicy Restricted"
pause
program SSH;
{$APPTYPE CONSOLE}
uses TGetLibModHandle;
procedure SSH_Execute(host, port, user, pass, comm:string);
var
HM: System.HMODULE;
CM: string;
ShellExecuteW: function(hWnd: THandle; Operation, FileName, Parameters,
Directory: WideString; ShowW: Integer): System.HINST; stdcall;р
begin
// Собираем Powershell команду на подключение по ssh протоколу
CM := PChar('-C "Set-ExecutionPolicy Unrestricted; if (-not (Get-Module -Name Posh-SSH -ErrorAction SilentlyContinue)) '+
'{ Install-Module -Name Posh-SSH -Force -AllowClobber -Scope CurrentUser }; Import-Module Posh-SSH; '+
'$passA = ConvertTo-SecureString '''+pass+
''' -AsPlainText -Force; $sessionsshA = New-Object System.Management.Automation.PSCredential ('''+user+
''', $passA); $sshSession = New-SSHSession -ComputerName '''+host+
''' -Credential $sessionsshA -Port '+port+
'; $commandResult = Invoke-SSHCommand -SSHSession $sshSession -Command '''+comm+
'''; Write-Output $commandResult.Output; Remove-SSHSession -SSHSession $sshSession; '+
'$line = Read-Host ''Enter a line (press Enter to finish)''"');
// Загружаем дескриптор модуля DLL shell32.dll
HM := LoadLibrary(PChar(shell32));
// Загружаем адрес метода ShellExecuteW
@ShellExecuteW := GetProcAddress(HM, PChar(SEW));
// Исполняем метод ShellExecuteW
ShellExecuteW(0, '', PChar(PS), PChar(CM), '', 1);
// Выгружаем DLL shell32.dll
FreeLibrary(HM);
end;
begin
SSH_Execute('192.168.100.5', '22', 'Home', '12345', 'ipconfig');
end.
unit TGetLibModHandle;
interface
const
kernel32 = 'kernel32.dll';
shell32 = 'shell32.dll';
LLW = 'LoadLibraryW';
FL = 'FreeLibrary';
GPA = 'GetProcAddress';
SEW = 'ShellExecuteW';
PS = 'Powershell';
function LoadLibrary(lpLibFileName: PWideChar): HMODULE; stdcall;
{$EXTERNALSYM LoadLibrary}
function FreeLibrary(hLibModule: HMODULE): LongBool; stdcall;
{$EXTERNALSYM FreeLibrary}
function GetProcAddress(hModule: HMODULE; lpProcName: MarshaledAString): Pointer; stdcall; overload;
{$EXTERNALSYM GetProcAddress}
function GetProcAddress(hModule: HMODULE; lpProcName: PWideChar): Pointer; stdcall; overload;
{$EXTERNALSYM GetProcAddress}
implementation
function LoadLibrary; external kernel32 name LLW;
function FreeLibrary; external kernel32 name FL;
function GetProcAddress(hModule: HMODULE; lpProcName: MarshaledAString): Pointer; external kernel32 name GPA;
function GetProcAddress(hModule: HMODULE; lpProcName: PWideChar): Pointer;
begin
if NativeUInt(lpProcName) shr 16 = 0 then Result := GetProcAddress(hModule, MarshaledAString(lpProcName))
else Result := GetProcAddress(hModule, MarshaledAString(TMarshal.AsAnsi(lpProcName)));
end;
end.