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