[Lazarus] MAC Address on Linux

ik idokan at gmail.com
Mon May 10 22:54:58 CEST 2010


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/


2010/5/10 Leonardo M. <l.rame at griensu.com>

> Hi, does anyone knows how to get the MAC address of a NIC using
> Lazarus/FPC on Linux?.
>
> P.S.: I found plenty of examples using Delphi's "Nb30" unit, only for
> Windows.
>
> --
> Leonardo M. Ramé
> Griensu S.A. - Medical IT Córdoba
> Tel.: 0351-4247979
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20100510/d4978994/attachment-0004.html>


More information about the Lazarus mailing list