Last active
January 15, 2017 11:50
-
-
Save ccy/d9132c3adc84a8c6d366c03c5daa57e8 to your computer and use it in GitHub Desktop.
Enumerate Network Interfaces in Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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