[Lazarus] MAC Address on Linux

silvioprog silvioprog at gmail.com
Mon May 10 22:59:30 CEST 2010


Em 10-05-2010 17:54, ik escreveu:
> Here is a simple example on how to read device MAC address in Linux
> 
> {$mode objfpc}
> program get_mac;
> uses sysutils;
> 
> const
>   linux_path     = '/sys/class/net/%s/address';
>   default_device = 'eth0';
> 
> var
>   f       : textfile;
>   device,
>   path,
>   addr    : string;
> 
> begin
>   device := default_device;
> 
>   if (ParamCount = 1) then
>     begin
>         device := ParamStr(1);
>     end;
> 
>    path := Format(linux_path,[device]);
>    if Not FileExists(path) then
>      begin
>        writeln('Could not find the device: ', device);
>        halt(1);
>      end;
> 
>   AssignFile(f, path);
>   reset(f);
>   readln(f,addr);
>   closefile(f);
> 
>   writeln(device, ' MAC Address: ', addr);
> end.
> 
> Ido
> http://ik.homelinux.org/

Worked perfectely on Ubuntu 10.04. Thanks Ido ;)

-- 
Silvio Clécio - <http://silvioprog.com.br>




More information about the Lazarus mailing list