-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPingThread.pas
More file actions
72 lines (59 loc) · 1.64 KB
/
Copy pathPingThread.pas
File metadata and controls
72 lines (59 loc) · 1.64 KB
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
unit PingThread;
interface
uses Windows, Classes, PingSend, IPUtils, SysUtils, WinSock;
type
PPingResult = ^TPingResult;
TPingResult = Record
IPAdress:String;
MacAdress:String;
Exists:Boolean;
end;
type
TPingThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
public
PingResult:TPingResult;
Ready:Boolean;
constructor Create(Ping:TPingResult);
end;
function SendARP(DestIp: DWORD; srcIP: DWORD; pMacAddr: pointer; PhyAddrLen: Pointer): DWORD;stdcall; external 'iphlpapi.dll';
implementation
function MySendARP(const IPAddress: String): String;
var
DestIP: ULONG;
MacAddr: Array [0..5] of Byte;
MacAddrLen: ULONG;
SendArpResult: Cardinal;
begin
DestIP := inet_addr(PAnsiChar(AnsiString(IPAddress)));
MacAddrLen := Length(MacAddr);
SendArpResult := SendARP(DestIP, 0, @MacAddr, @MacAddrLen);
if SendArpResult = NO_ERROR then
Result := Format('%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X',
[MacAddr[0], MacAddr[1], MacAddr[2],
MacAddr[3], MacAddr[4], MacAddr[5]])
else
Result := '';
end;
{ TPingThread }
constructor TPingThread.Create(Ping:TPingResult);
begin
PingResult.IPAdress := Ping.IPAdress;
inherited Create(False);
end;
procedure TPingThread.Execute;
var Ping:TPingSend;
begin
Ready := False;
Ping := TPingSend.Create;
Ping.Timeout := 500;
PingResult.Exists := Ping.Ping(PingResult.IPAdress);
if PingResult.Exists then
PingResult.MacAdress := MySendARP(PingResult.IPAdress);
Ping.Free;
Ready := true;
end;
end.