unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
const
MAX_ADAPTER_DESCRIPTION_LENGTH = 128;
// arb.
MAX_ADAPTER_NAME_LENGTH = 256;
// arb.
MAX_ADAPTER_ADDRESS_LENGTH = 8;
// arb.
type
PIP_ADDRESS_STRING = ^IP_ADDRESS_STRING;
IP_ADDRESS_STRING =
packed record
acString :
array [1..16]
of Char;
end;
PIP_MASK_STRING = ^PIP_MASK_STRING;
IP_MASK_STRING = IP_ADDRESS_STRING;
PIP_ADDR_STRING = ^IP_ADDR_STRING;
IP_ADDR_STRING =
packed record
Next : PIP_ADDR_STRING;
IpAddress : IP_ADDRESS_STRING;
IpMask : IP_MASK_STRING;
Context : DWORD;
end;
time_t = int64;
PIP_ADAPTER_INFO = ^IP_ADAPTER_INFO;
IP_ADAPTER_INFO =
packed record
Next : PIP_ADAPTER_INFO;
ComboIndex : DWORD;
AdapterName :
array [1..MAX_ADAPTER_NAME_LENGTH+4]
of Char ;
Description :
array [1..MAX_ADAPTER_DESCRIPTION_LENGTH+4]
of Char;
AddressLength : UINT;
Address :
array [1..MAX_ADAPTER_ADDRESS_LENGTH]
of Byte;
Index : DWORD;
dwType : UINT;
DhcpEnabled : UINT;
CurrentIpAddress : PIP_ADDR_STRING;
IpAddressList : IP_ADDR_STRING;
GatewayList : IP_ADDR_STRING;
DhcpServer : IP_ADDR_STRING;
HaveWins : Boolean;
PrimaryWinsServer : IP_ADDR_STRING;
SecondaryWinsServer : IP_ADDR_STRING;
LeaseObtained : time_t;
LeaseExpires : time_t;
end;
function GetAdaptersInfo(
const pAdapterInfo : PIP_ADAPTER_INFO;
const pOutBufLen : PULONG) : DWORD;
stdcall;
external '
IPHLPAPI.DLL'
name '
GetAdaptersInfo';
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
dwResult : DWORD;
dwLen : DWORD;
pAdapterWork : PIP_ADAPTER_INFO;
pAdapterList : PIP_ADAPTER_INFO;
iasWork : IP_ADDR_STRING;
begin
pAdapterList :=
nil;
dwLen := 0;
dwResult := GetAdaptersInfo(pAdapterList,@dwLen);
if dwResult = ERROR_BUFFER_OVERFLOW
then
begin
pAdapterList := AllocMem(dwLen);
try
dwResult := GetAdaptersInfo(pAdapterList,@dwLen);
if dwResult = ERROR_SUCCESS
then
begin
pAdapterWork := pAdapterList;
ComboBox1.Clear;
repeat
iasWork := pAdapterWork.GatewayList;
while iasWork.Next <>
nil do
begin
ComboBox1.Items.Add(trim(iasWork.IpAddress.acString));
iasWork := iasWork.Next^;
end;
ComboBox1.Items.Add(trim(iasWork.IpAddress.acString));
pAdapterWork := pAdapterWork.Next;
until pAdapterWork =
nil;
if ComboBox1.Items.Count > 0
then
begin
ComboBox1.ItemIndex := 0;
end;
end;
finally
FreeMem(pAdapterList,dwLen);
end;
end;
end;
end.