procedure TfrmMain.RetrieveLocalAdapterInformation;
var
pAdapters, pAdapter: PIP_ADAPTER_INFO;
pIPAddress: PIP_ADDR_STRING;
BufLen: DWORD;
Status: DWORD;
strMAC: String;
i: Integer;
strings: TStrings;
begin
strings := TStringList.Create;
try
BufLen := 1024*15;
pAdapters := AllocMem(BufLen);
try
repeat
Status := GetAdaptersInfo(pAdapters, BufLen);
if (Status <> ERROR_BUFFER_OVERFLOW) then Break;
ReallocMem(pAdapters, BufLen);
until False;
if (Status = ERROR_SUCCESS) and (BufLen = 0) then
Status := ERROR_NO_DATA;
if (Status <> ERROR_SUCCESS) then
begin
case Status of
ERROR_NOT_SUPPORTED:
strings.Add('GetAdaptersInfo is not supported by the operating ' +
'system running on the local computer.');
ERROR_NO_DATA:
strings.Add('No network adapter on the local computer.');
else
strings.Add('GetAdaptersInfo failed with error #' + IntToStr(Status));
end;
Exit;
end;
pAdapter := pAdapters;
repeat
Memo1.Lines.Add('');
Memo1.Lines.Add('Description: ------------------------' + string(pAdapter^.Description));
Memo1.Lines.Add('Name: ' + string(pAdapter^.AdapterName));
strMAC := '';
for I := 0 to pAdapter^.AddressLength - 1 do
strMAC := strMAC + '-' + IntToHex(pAdapter^.Address[I], 2);
Delete(strMAC, 1, 1);
Memo1.Lines.Add('MAC address: ' + strMAC);
pIPAddress := @pAdapter^.IpAddressList;
repeat
Memo1.Lines.Add('IP address: ' + string(pIPAddress^.IpAddress.S));
Memo1.Lines.Add('IP subnet mask: ' + string(pIPAddress^.IpMask.S));
pIPAddress := pIPAddress^.Next;
until (pIPAddress = nil);
//pIPAddress := @pAdapter^.GatewayList;
//repeat
// Memo1.Lines.Add('Gateway: ' + string(pIPAddress^.IpAddress.S));
// pIPAddress := pIPAddress^.Next;
//until (pIPAddress = nil);
//Memo1.Lines.Add('DHCP enabled: ' + IntToStr(pAdapter^.DhcpEnabled));
//Memo1.Lines.Add('DHCP: ' + pAdapter^.DhcpServer.IpAddress.S);
//Memo1.Lines.Add('Have WINS: ' + BoolToStr(pAdapter^.HaveWins,True));
//Memo1.Lines.Add('Primary WINS: ' + pAdapter^.PrimaryWinsServer.IpAddress.S);
//pIPAddress := @pAdapter^.SecondaryWinsServer;
//repeat
// Memo1.Lines.Add('Secondary WINS: ' + string(pIPAddress^.IpAddress.S));
// pIPAddress := pIPAddress^.Next;
//until (pIPAddress = nil);
pAdapter := pAdapter^.Next;
until (pAdapter = nil);
finally
Dispose(pAdapters);
end;
finally
strings.Free;
end;
end;