Skip to content

Instantly share code, notes, and snippets.

@ccy
Last active January 15, 2017 11:50
Show Gist options
  • Save ccy/d9132c3adc84a8c6d366c03c5daa57e8 to your computer and use it in GitHub Desktop.
Save ccy/d9132c3adc84a8c6d366c03c5daa57e8 to your computer and use it in GitHub Desktop.
Enumerate Network Interfaces in Windows
uses
System.SysUtils,
Winapi.Windows,
Winapi.IpTypes,
Winapi.IpHlpApi;
var
Adapter, Current: PIP_ADAPTER_ADDRESSES;
Buffer: NativeInt;
Error: DWord;
begin
ReportMemoryLeaksOnShutdown := True;
Error := GetAdaptersAddresses(0, 0, nil, nil, @Buffer);
Assert(Error = ERROR_BUFFER_OVERFLOW);
Adapter := AllocMem(Buffer);
try
Error := GetAdaptersAddresses(0, 0, nil, Adapter, @Buffer);
Assert(Error = ERROR_SUCCESS);
Current := Adapter;
while Current <> nil do begin
WriteLn(Current.FriendlyName);
Current := Current.Next;
end;
finally
FreeMem(Adapter);
end;
ReadLn;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment