-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpingtrd.pas
85 lines (65 loc) · 1.5 KB
/
pingtrd.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
unit PingTRD;
{$mode objfpc}{$H+}
interface
uses
Classes, Forms, Controls, SysUtils, Process, Graphics;
type
CheckPing = class(TThread)
private
{ Private declarations }
protected
var
PingStr: TStringList;
procedure Execute; override;
procedure ShowStatus;
end;
implementation
uses unit1;
{ TRD }
procedure CheckPing.Execute;
var
PingProcess: TProcess;
begin
try
FreeOnTerminate := True; //Уничтожать по завершении
PingStr := TStringList.Create;
PingProcess := TProcess.Create(nil);
PingProcess.Executable := 'bash';
while not Terminated do
begin
PingProcess.Parameters.Clear;
PingProcess.Parameters.Add('-c');
PingProcess.Parameters.Add(
'[[ $(fping google.com) && $(systemctl is-active sshuttle) == "active" ]] && echo "yes" || echo "no"');
PingProcess.Options := [poUsePipes, poWaitOnExit];
PingProcess.Execute;
PingStr.LoadFromStream(PingProcess.Output);
Synchronize(@ShowStatus);
Sleep(500);
end;
finally
PingStr.Free;
PingProcess.Free;
Terminate;
end;
end;
//Индикация: светодиод, режим
procedure CheckPing.ShowStatus;
begin
with MainForm do
begin
if Trim(PingStr[0]) = 'yes' then
begin
StartBtn.Caption := SStop;
Shape1.Brush.Color := clLime;
end
else
begin
StartBtn.Caption := SStart;
Shape1.Brush.Color := clYellow;
end;
Shape1.Repaint;
StartBtn.Repaint;
end;
end;
end.