Board index » delphi » How Can I read the MAC address from the LAN card

How Can I read the MAC address from the LAN card

I want to read the MAC address of the Network card so that my program can
validate whether the machine has bought a software license from me. I am
afraid my customers just copy my software to many machines and use.

Please help.

 

Re:How Can I read the MAC address from the LAN card


With thanks to Mr. Piette:

Using IP Helper API (see www.delphi-jedi.org for Delphi port). Here is some
code I wrote which might help you (If you use it, please give me some
credit):

uses IpTypes, IpHlpApi;

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*}
function IpListToStr(pIpAddr : PIP_ADDR_STRING) : String;
begin
   Result := '';
   repeat
       Result := Result + ', ' + Pchar(Addr(pIpAddr^.IpAddress));
       pIpAddr := pIpAddr.Next;
   until pIpAddr = nil;
   Delete(Result, 1, 2);
   if Result = '' then
       Result := 'none';
end;

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*}
procedure TIfConfForm.DisplayIfConf;
var
   AdapterInfo  : IP_ADAPTER_INFO;
   pAdapterInfo : PIP_ADAPTER_INFO;
   BufSize      : DWORD;
   Status       : DWORD;
   I            : Integer;
   Buf          : String;
const
   BooleanToStr : array [Boolean] of String = ('FALSE', 'TRUE');
begin
   DisplayMemo.Clear;
   BufSize      := SizeOf(AdapterInfo);
   pAdapterInfo := @AdapterInfo;
   Status       := GetAdaptersInfo(pAdapterInfo, BufSize);
   if Status <> ERROR_SUCCESS then begin
       case Status of
       ERROR_NOT_SUPPORTED :
           Display('GetAdaptersInfo is not supported by the operating ' +
                   'system running on the local computer.');
       ERROR_NO_DATA :
           Display('No network adapter on the local computer.');
       else
           Display('GetAdaptersInfo failed with error #' +
IntToStr(Status));
       end;
       Exit;
   end;
   repeat
       Display('Description:    ' + pAdapterInfo^.Description);
       Display('Name:           ' + pAdapterInfo^.AdapterName);

       Buf := '';
       for I := 0 to pAdapterInfo^.AddressLength - 1 do
           Buf := Buf + '-' + IntToHex(pAdapterInfo^.Address[I], 2);
       Delete(Buf, 1, 1);
       Display('MAC address:    ' + Buf);

       Display('IP address:     ' +
IpListToStr(@pAdapterInfo^.IpAddressList));
       Display('Gateway:        ' +
IpListToStr(@pAdapterInfo^.GatewayList));
       DIsplay('DHCP enabled:   ' + BooleanToStr[pAdapterInfo^.DhcpEnabled
<> 0]);
       Display('DHCP:           ' + IpListToStr(@pAdapterInfo^.DhcpServer));
       DIsplay('Have WINS:      ' + BooleanToStr[pAdapterInfo^.HaveWins]);
       Display('Primary WINS:   ' +
IpListToStr(@pAdapterInfo^.PrimaryWinsServer));
       Display('Secondary WINS: ' +
IpListToStr(@pAdapterInfo^.SecondaryWinsServer));

       pAdapterInfo := pAdapterInfo^.Next;
   until pAdapterInfo = nil;
   Display('Done.');
end;

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*}

--
francois.pie...@overbyte.be
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be

Re:How Can I read the MAC address from the LAN card


"J.A. Korten" <a.kor...@chello.nl> wrote in newsgroup:
news:3beaaa63_2@dnews...

Quote
> With thanks to Mr. Piette:

> Using IP Helper API (see www.delphi-jedi.org for Delphi port). Here is
some
> code I wrote which might help you (If you use it, please give me some
> credit):
<Skip>

I think highly about Mr. Piette and have programs that use ICS but there
will be a problem
if you have more than one adapter on your system. I prefer dynamically get
memory for AdapterInfo
structures and then free it after using. You can see an example in Demo
project in IpHlpApi.zip

--
Best Regards,
Vladimir Vassiliev
http://voldemarv.virtualave.net

Other Threads