ehsan_faal
چهارشنبه 07 شهریور 1397, 11:37 صبح
سلام.
با استفاده از chilkat یه برنامه نوشتم که با ssh به روتربوردی که تو اتاق سرور هست و فقط برای چک کردن وضعیت برق شهر اونجا گذاشته شده، آپ تایمش رو بخونم.
با وینباکس هم میشه اینکار رو کرد اما وینباکس در صورت disconnect شدن هیچ alarm صداداری نمیده و فقط میگه که reconnect کن.
مشکلاتی که دارم اینا هستن:
۱- برنامه resource زیادی میکشه. از خود وینباکس با اونهمه امکانات هم بیشتر.
۲- توی لاگ روتر با هر بار فراخوانی تابع مربوط به ssh یه خط connect و disconnectمیاد در صورتی که من یک بار فقط session رو ایجاد و یک بار هم بستمش.
۳- dll های این کتابخونه رو نیمشه به خود فایل نهایی attach کرد؟
اینم کدی که استفاده میکنم در حال حاضر:
راه بهینه تری پیشنهاد بدید عالی میشه:
Program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
{$R 'MYDDL.res' 'MYDDL.rc'}
Uses
System.SysUtils,
System.StrUtils,
Ssh;
Var
Ssh: HCkSsh;
cmdOutput: PWideChar;
Procedure RunSSH;
Var
success: Boolean;
port: Integer;
host: PWideChar;
channelNum: Integer;
Begin
Ssh := CkSsh_Create();
success := CkSsh_UnlockComponent(Ssh, 's2yjlR.CB10750_Ig3zlV2R4C77');
If (success <> True) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
port := ****;
host := '192.168.185.254';
success := CkSsh_Connect(Ssh, host, port);
If (success <> True) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
CkSsh_putIdleTimeoutMs(Ssh, 5000);
success := CkSsh_AuthenticatePw(Ssh, '****', '*****');
If (success <> True) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
channelNum := CkSsh_OpenSessionChannel(Ssh);
If (channelNum < 0) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
success := CkSsh_SendReqExec(Ssh, channelNum, 'system resource print');
If (success <> True) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
success := CkSsh_ChannelReceiveToClose(Ssh, channelNum);
If (success <> True) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
cmdOutput := CkSsh__getReceivedText(Ssh, channelNum, 'ansi');
If (CkSsh_getLastMethodSuccess(Ssh) <> True) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
End;
Begin
Try
While True Do
Begin
RunSSH;
Writeln(Trim(LeftStr(cmdOutput, Pos(#10, cmdOutput))));
Sleep(5000);
End;
Finally
CkSsh_Disconnect(Ssh);
CkSsh_Dispose(Ssh);
End;
Readln;
End.
با استفاده از chilkat یه برنامه نوشتم که با ssh به روتربوردی که تو اتاق سرور هست و فقط برای چک کردن وضعیت برق شهر اونجا گذاشته شده، آپ تایمش رو بخونم.
با وینباکس هم میشه اینکار رو کرد اما وینباکس در صورت disconnect شدن هیچ alarm صداداری نمیده و فقط میگه که reconnect کن.
مشکلاتی که دارم اینا هستن:
۱- برنامه resource زیادی میکشه. از خود وینباکس با اونهمه امکانات هم بیشتر.
۲- توی لاگ روتر با هر بار فراخوانی تابع مربوط به ssh یه خط connect و disconnectمیاد در صورتی که من یک بار فقط session رو ایجاد و یک بار هم بستمش.
۳- dll های این کتابخونه رو نیمشه به خود فایل نهایی attach کرد؟
اینم کدی که استفاده میکنم در حال حاضر:
راه بهینه تری پیشنهاد بدید عالی میشه:
Program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
{$R 'MYDDL.res' 'MYDDL.rc'}
Uses
System.SysUtils,
System.StrUtils,
Ssh;
Var
Ssh: HCkSsh;
cmdOutput: PWideChar;
Procedure RunSSH;
Var
success: Boolean;
port: Integer;
host: PWideChar;
channelNum: Integer;
Begin
Ssh := CkSsh_Create();
success := CkSsh_UnlockComponent(Ssh, 's2yjlR.CB10750_Ig3zlV2R4C77');
If (success <> True) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
port := ****;
host := '192.168.185.254';
success := CkSsh_Connect(Ssh, host, port);
If (success <> True) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
CkSsh_putIdleTimeoutMs(Ssh, 5000);
success := CkSsh_AuthenticatePw(Ssh, '****', '*****');
If (success <> True) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
channelNum := CkSsh_OpenSessionChannel(Ssh);
If (channelNum < 0) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
success := CkSsh_SendReqExec(Ssh, channelNum, 'system resource print');
If (success <> True) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
success := CkSsh_ChannelReceiveToClose(Ssh, channelNum);
If (success <> True) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
cmdOutput := CkSsh__getReceivedText(Ssh, channelNum, 'ansi');
If (CkSsh_getLastMethodSuccess(Ssh) <> True) Then
Begin
Writeln(CkSsh__lastErrorText(Ssh));
Exit;
End;
End;
Begin
Try
While True Do
Begin
RunSSH;
Writeln(Trim(LeftStr(cmdOutput, Pos(#10, cmdOutput))));
Sleep(5000);
End;
Finally
CkSsh_Disconnect(Ssh);
CkSsh_Dispose(Ssh);
End;
Readln;
End.