This repository was archived by the owner on Oct 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathugetmacadress.pas
More file actions
57 lines (50 loc) · 1.37 KB
/
ugetmacadress.pas
File metadata and controls
57 lines (50 loc) · 1.37 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
unit UGetMacAdress;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Process;
type
TGetMacAdress = class
public
function getMac: string;
end;
implementation
function TGetMacAdress.getMac: string;
var
process: TProcess;
response: TStringList;
address: TStringList;
begin
{$IFDEF WINDOWS}
process:=TProcess.create(nil);
process.executable:='cmd.exe';
process.parameters.add('/C getmac -fo csv');
process.options:=process.options + [poWaitOnExit, poUsePipes];
process.showWindow:=swoHIDE;
process.execute;
response:=TStringList.create;
response.LoadFromStream(process.output);
process.free;
address:=TStringList.create;
address.delimiter:=',';
address.delimitedText:=response[1];
response.free;
result:=StringReplace(address[0], '-', ':', [rfReplaceAll]);
address.free;
{$ENDIF}
{$IFDEF LINUX}
process:=TProcess.create(nil);
process.executable:='sh';
process.parameters.add('-c');
process.parameters.add('cat /sys/class/net/$(ip route show default | awk ''/default/ {print $5}'')/address');
process.options:=process.options + [poWaitOnExit, poUsePipes];
process.showWindow:=swoHIDE;
process.execute;
response:=TStringList.create;
response.LoadFromStream(process.output);
process.free;
result:=UpperCase(response[0]);
response.free;
{$ENDIF}
end;
end.