Delphi Linux getting MacAddress
In linux every adapter configuration has a file system path, for example the adapter eth0 has all configuration, in some text files located in “/sys/class/net/eth0/”.
The file whose name is “address” contains a single line with the mac adrress value.
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 |
function GetLinuxMacAddress(device_name : String): string; const linux_path = '/sys/class/net/%s/address'; var f : textfile; device, path, addr : string; begin Result := ''; path := Format(linux_path,[device_name]); if (not FileExists(path)) then begin Result := ''; end else begin AssignFile(f, path); reset(f); readln(f, addr); closefile(f); Result := addr; end; end; |