Delphi 获取有关已安装网络适配器的信息

Delphi 获取有关已安装网络适配器的信息,delphi,delphi-xe2,winsock,Delphi,Delphi Xe2,Winsock,我正在Windows XP sp3上使用Delphi XE2 Update 4 我希望从安装的网络适配器(特别是广播ip)获得尽可能多的信息 为此,我使用了Jan Schulz的代码 单位: 代码显然是有效的,但是它只返回一个网络接口,即环回(127.0.0.0),它还应该返回我的网络专用接口 在代码的这一部分,它总是只返回一个可用接口: NoOfInterfaces:=noofbytes返回的Div SizeOf(接口信息) 要在XE2上工作,我必须更改使用的字符串(AnsiString) 我

我正在Windows XP sp3上使用Delphi XE2 Update 4

我希望从安装的网络适配器(特别是广播ip)获得尽可能多的信息

为此,我使用了Jan Schulz的代码

单位:

代码显然是有效的,但是它只返回一个网络接口,即环回(127.0.0.0),它还应该返回我的网络专用接口

在代码的这一部分,它总是只返回一个可用接口:

NoOfInterfaces:=noofbytes返回的Div SizeOf(接口信息)

要在XE2上工作,我必须更改使用的字符串(AnsiString)

我也尝试过使用Winsock2单元,也尝试过使用IdWinSock2和API调用

在所有情况下,API都工作并仅返回环回接口

使用另一个在delphi上编写的实用程序,我可以得到一个这个列表,并且列出了本地IP 192.168.0.112,但是这个源代码不容易使用


我的问题是:怎么了?

当您将字符串声明更改为AnsiString时,也将Char声明更改为AnsiChar。

Jan Schulz的代码在正确转换为unicode友好的Delphi时运行良好

我做了一些更正:

  • 如前所述,
    char
    必须在需要时转换为
    AnsiChar
    。在这种情况下,这只会发生在
    SockAddr\u Gen
    记录的
    Padding
    字段中,该字段不仅会扭曲记录,还会导致
    SizeOf(Interface\u Info)
    ,随后
    NoOfInterfaces
    ,返回错误结果。因为它不是一个真正的字符,所以最好将其定义为
    字节

  • 丢弃的
    PChars
    用于保存
    inet\u ntoa
    调用的结果,并直接分配
    TNetworkInterface
    字符串字段

  • TNetworkInterface
    中的
    字符串
    没有问题,因为它们不会传递给任何api调用。另外,
    ComputerName
    被传递到
    GetComputerName
    api,它需要一个
    PWideChar
    /
    PChar


unitusock;
接口
使用Windows、Winsock;
{识别网络接口的单元
此代码至少需要Win98/ME/2K、95 OSR 2或NT service pack#3
使用WinSock 2时(WS2_32.DLL)}
//手册中关于非官方文档M$Winsock函数的常量
Const SIO_GET_INTERFACE_LIST=$4004747F;
IFF_UP=$00000001;
IFF_广播=00000002美元;
IFF_环回=$00000004;
IFF_POINTTOPOINT=$00000008;
IFF_多播=$00000010;
类型SockAddr\u Gen=打包记录
地址:SockAddr_In;
填充:字节的压缩数组[0..7];
结束;
接口信息=记录
iiFlags:u_Long;
地址:SockAddr_Gen;
地址:SockAddr_Gen;
网络掩码:SockAddr_Gen;
结束;
t网络接口=记录
计算机名称:字符串;
AddrIP:字符串;
子网掩码:字符串;
地址:字符串;
AddrLimitedBroadcast:字符串;
AddrDirectedBroadcast:字符串;
IsInterfaceUp:布尔值;
支持:布尔;
IsLoopback:布尔值;
结束;
tNetworkInterface列表=tNetworkInterface的数组;
函数WSAIoctl(aSocket:TSocket;
命令:德沃德;
lpInBuffer:指针;
德温:德沃德;
LPF:指针;
德弗伦:德沃德;
lpdwoutbytes返回:LPDWord;
lpOverLapped:指针;
lpOverLappedRoutine:指针):整数;stdcall;外部“WS2_32.DLL”;
函数GetNetworkInterfaces(Var aNetworkInterfaceList:tNetworkInterfaceList):布尔值;
实施
函数GetNetworkInterfaces(Var aNetworkInterfaceList:tNetworkInterfaceList):布尔值;
//返回系统(IPv4)上可用网络接口的完整列表
//Jan Schulz博士版权所有,2007年3月23日至26日
//此版本可用于免费和非营利项目。在任何其他情况下,请联系
//使用从MSDN检索到的信息编写
//www.code10.net
变量aSocket:TSocket;
awsadata记录:WSAData;
NoOfInterfaces:整数;
无细胞返回:u_Long;
接口标签:u_Long;
名称长度:DWord;
pAddrIP:SockAddr_In;
pAddrSubnetMask:SockAddr_In;
pAddrBroadcast:Sockaddr_In;
地址:In_Addr;
NetAddressDummy:In_Addr;
缓冲区:接口信息的数组[0..30];
i:整数;
开始
结果:=假;
SetLength(aNetworkInterfaceList,0);
//旧WinSock的启动
//WSAStartup(0101美元,aWSADataRecord);
//WinSock2的启动
WSAStartup(MAKEWORD(2,0),awsadata记录);
//打开插座
aSocket:=套接字(AF\u INET,SOCK\u STREAM,0);
//如果不可能打开插座,就不值得再进一步了
如果(aSocket=INVALID_SOCKET),则退出;
尝试
如果WSAIoCtl(aSocket,SIO_GET_INTERFACE_LIST,NIL,0,
@缓冲区,1024,@noofbytes返回,零,
Unit USock;

Interface

Uses Windows, Winsock;

{ Unit to identify the network interfaces
  This code requires at least Win98/ME/2K, 95 OSR 2 or NT service pack #3
  as WinSock 2 is used (WS2_32.DLL) }


// Constants found in manual on non-officially documented M$ Winsock functions
Const SIO_GET_INTERFACE_LIST = $4004747F;
      IFF_UP                 = $00000001;
      IFF_BROADCAST          = $00000002;
      IFF_LOOPBACK           = $00000004;
      IFF_POINTTOPOINT       = $00000008;
      IFF_MULTICAST          = $00000010;


Type SockAddr_Gen          = Packed Record
                               AddressIn             : SockAddr_In;
                               Padding               : Packed Array [0..7] of Char;
                             end;

     Interface_Info        = Record
                               iiFlags               : u_Long;
                               iiAddress             : SockAddr_Gen;
                               iiBroadcastAddress    : SockAddr_Gen;
                               iiNetmask             : SockAddr_Gen;
                             end;

     tNetworkInterface     = Record
                               ComputerName          : String;
                               AddrIP                : String;
                               SubnetMask            : String;
                               AddrNet               : String;
                               AddrLimitedBroadcast  : String;
                               AddrDirectedBroadcast : String;
                               IsInterfaceUp         : Boolean;
                               BroadcastSupport      : Boolean;
                               IsLoopback            : Boolean;
                             end;

     tNetworkInterfaceList = Array of tNetworkInterface;


Function WSAIoctl (aSocket              : TSocket;
                   aCommand             : DWord;
                   lpInBuffer           : PChar;
                   dwInBufferLen        : DWord;
                   lpOutBuffer          : PChar;
                   dwOutBufferLen       : DWord;
                   lpdwOutBytesReturned : LPDWord;
                   lpOverLapped         : Pointer;
                   lpOverLappedRoutine  : Pointer) : Integer; stdcall; external 'WS2_32.DLL';

Function GetNetworkInterfaces (Var aNetworkInterfaceList : tNetworkInterfaceList): Boolean;



Implementation

Function GetNetworkInterfaces (Var aNetworkInterfaceList : tNetworkInterfaceList): Boolean;
// Returns a complete list the of available network interfaces on a system (IPv4)
// Copyright by Dr. Jan Schulz, 23-26th March 2007
// This version can be used for free and non-profit projects. In any other case get in contact
// Written with information retrieved from MSDN
// www.code10.net
Var aSocket             : TSocket;
    aWSADataRecord      : WSAData;
    NoOfInterfaces      : Integer;
    NoOfBytesReturned   : u_Long;
    InterfaceFlags      : u_Long;
    NameLength          : DWord;
    pAddrIP             : SockAddr_In;
    pAddrSubnetMask     : SockAddr_In;
    pAddrBroadcast      : Sockaddr_In;
    pIPString           : PChar;
    pSubnetMaskString   : PChar;
    pLimBroadcastString : PChar;
    pNetAddrString      : PChar;
    pDirBroadcastString : PChar;
    DirBroadcastDummy   : In_Addr;
    NetAddrDummy        : In_Addr;
    Buffer              : Array [0..30] of Interface_Info;
    i                   : Integer;
Begin
  Result := False;
  SetLength (aNetworkInterfaceList, 0);

  // Startup of old the WinSock
  // WSAStartup ($0101, aWSADataRecord);

  // Startup of WinSock2
  WSAStartup(MAKEWORD(2, 0), aWSADataRecord);

  // Open a socket
  aSocket := Socket (AF_INET, SOCK_STREAM, 0);

  // If impossible to open a socket, not worthy to go any further
  If (aSocket = INVALID_SOCKET) THen Exit;

  Try
    If WSAIoCtl (aSocket, SIO_GET_INTERFACE_LIST, NIL, 0,
                 @Buffer, 1024, @NoOfBytesReturned, NIL, NIL) <> SOCKET_ERROR THen
    Begin
      NoOfInterfaces := NoOfBytesReturned  Div SizeOf (Interface_Info);
      SetLength (aNetworkInterfaceList, NoOfInterfaces);

      // For each of the identified interfaces get:
      For i := 0 to NoOfInterfaces - 1 do
      Begin

        With aNetworkInterfaceList[i] do
        Begin

          // Get the name of the machine
          NameLength := MAX_COMPUTERNAME_LENGTH + 1;
          SetLength (ComputerName, NameLength)  ;
          If Not Windows.GetComputerName (PChar (Computername), NameLength) THen ComputerName := '';

          // Get the IP address
          pAddrIP                  := Buffer[i].iiAddress.AddressIn;
          pIPString                := inet_ntoa (pAddrIP.Sin_Addr);
          AddrIP                   := pIPString;

          // Get the subnet mask
          pAddrSubnetMask          := Buffer[i].iiNetMask.AddressIn;
          pSubnetMaskString        := inet_ntoa (pAddrSubnetMask.Sin_Addr);
          SubnetMask               := pSubnetMaskString;

          // Get the limited broadcast address
          pAddrBroadcast           := Buffer[i].iiBroadCastAddress.AddressIn;
          pLimBroadcastString      := inet_ntoa (pAddrBroadcast.Sin_Addr);
          AddrLimitedBroadcast     := pLimBroadcastString;

          // Calculate the net and the directed broadcast address
          NetAddrDummy.S_addr      := Buffer[i].iiAddress.AddressIn.Sin_Addr.S_Addr;
          NetAddrDummy.S_addr      := NetAddrDummy.S_addr And Buffer[i].iiNetMask.AddressIn.Sin_Addr.S_Addr;
          DirBroadcastDummy.S_addr := NetAddrDummy.S_addr Or Not Buffer[i].iiNetMask.AddressIn.Sin_Addr.S_Addr;

          pNetAddrString           := inet_ntoa ((NetAddrDummy));
          AddrNet                  := pNetAddrString;

          pDirBroadcastString      := inet_ntoa ((DirBroadcastDummy));
          AddrDirectedBroadcast    := pDirBroadcastString;

          // From the evaluation of the Flags we receive more information
          InterfaceFlags           := Buffer[i].iiFlags;

          // Is the network interface up or down ?
          If (InterfaceFlags And IFF_UP) = IFF_UP THen IsInterfaceUp := True
                                                  Else IsInterfaceUp := False;

          // Does the network interface support limited broadcasts ?
          If (InterfaceFlags And IFF_BROADCAST) = IFF_BROADCAST THen BroadcastSupport := True
                                                                Else BroadcastSupport := False;

          // Is the network interface a loopback interface ?
          If (InterfaceFlags And IFF_LOOPBACK) = IFF_LOOPBACK THen IsLoopback := True
                                                              Else IsLoopback := False;
        end;
      end;
    end;
  Except
    Result := False;
  end;

  // Cleanup the mess
  CloseSocket (aSocket);
  WSACleanUp;
  Result := True;
end;

end.
uses USock; 

Procedure TForm1.Button1Click(Sender: TObject);
Var i                 : Integer;
    aNetInterfaceList : tNetworkInterfaceList;
Begin
  If (GetNetworkInterfaces (aNetInterfaceList)) THen
  Begin
    Memo1.Clear;
    Memo1.Lines.Add (DateTimeToStr (Now)+ ' : ');

    For i := 0 to High (aNetInterfaceList) do
    Begin
      Memo1.Lines.Add ('');
      Memo1.Lines.Add ('#                          : ' + IntToStr(i));
      Memo1.Lines.Add ('Name                       : ' + aNetInterfaceList[i].ComputerName);
      Memo1.Lines.Add ('IP-Address                 : ' + aNetInterfaceList[i].AddrIP);
      Memo1.Lines.Add ('Subnet mask                : ' + aNetInterfaceList[i].SubnetMask);
      Memo1.Lines.Add ('Net address                : ' + aNetInterfaceList[i].AddrNet);
      Memo1.Lines.Add ('Limited broadcast address  : ' + aNetInterfaceList[i].AddrLimitedBroadcast);
      Memo1.Lines.Add ('Directed Broadcast address : ' + aNetInterfaceList[i].AddrDirectedBroadcast);
      Memo1.Lines.Add ('Interface up               : ' + BoolToStr (aNetInterfaceList[i].IsInterfaceUp, True));
      Memo1.Lines.Add ('Broadcast supported        : ' + BoolToStr (aNetInterfaceList[i].BroadcastSupport, True));
      Memo1.Lines.Add ('Loopback interface         : ' + BoolToStr (aNetInterfaceList[i].IsLoopback, True));
      Memo1.Lines.Add ('');
    end;
  end;
end;
Unit USock;

Interface

Uses Windows, Winsock;


{ Unit to identify the network interfaces
  This code requires at least Win98/ME/2K, 95 OSR 2 or NT service pack #3
  as WinSock 2 is used (WS2_32.DLL) }


// Constants found in manual on non-officially documented M$ Winsock functions
Const SIO_GET_INTERFACE_LIST = $4004747F;
      IFF_UP                 = $00000001;
      IFF_BROADCAST          = $00000002;
      IFF_LOOPBACK           = $00000004;
      IFF_POINTTOPOINT       = $00000008;
      IFF_MULTICAST          = $00000010;


Type SockAddr_Gen          = Packed Record
                               AddressIn             : SockAddr_In;
                               Padding               : Packed Array [0..7] of Byte;
                             end;

     Interface_Info        = Record
                               iiFlags               : u_Long;
                               iiAddress             : SockAddr_Gen;
                               iiBroadcastAddress    : SockAddr_Gen;
                               iiNetmask             : SockAddr_Gen;
                             end;

     tNetworkInterface     = Record
                               ComputerName          : String;
                               AddrIP                : String;
                               SubnetMask            : String;
                               AddrNet               : String;
                               AddrLimitedBroadcast  : String;
                               AddrDirectedBroadcast : String;
                               IsInterfaceUp         : Boolean;
                               BroadcastSupport      : Boolean;
                               IsLoopback            : Boolean;
                             end;

     tNetworkInterfaceList = Array of tNetworkInterface;


Function WSAIoctl (aSocket              : TSocket;
                   aCommand             : DWord;
                   lpInBuffer           : Pointer;
                   dwInBufferLen        : DWord;
                   lpOutBuffer          : Pointer;
                   dwOutBufferLen       : DWord;
                   lpdwOutBytesReturned : LPDWord;
                   lpOverLapped         : Pointer;
                   lpOverLappedRoutine  : Pointer) : Integer; stdcall; external 'WS2_32.DLL';

Function GetNetworkInterfaces (Var aNetworkInterfaceList : tNetworkInterfaceList): Boolean;


implementation


Function GetNetworkInterfaces (Var aNetworkInterfaceList : tNetworkInterfaceList): Boolean;
// Returns a complete list the of available network interfaces on a system (IPv4)
// Copyright by Dr. Jan Schulz, 23-26th March 2007
// This version can be used for free and non-profit projects. In any other case get in contact
// Written with information retrieved from MSDN
// www.code10.net
Var aSocket             : TSocket;
    aWSADataRecord      : WSAData;
    NoOfInterfaces      : Integer;
    NoOfBytesReturned   : u_Long;
    InterfaceFlags      : u_Long;
    NameLength          : DWord;
    pAddrIP             : SockAddr_In;
    pAddrSubnetMask     : SockAddr_In;
    pAddrBroadcast      : Sockaddr_In;
    DirBroadcastDummy   : In_Addr;
    NetAddrDummy        : In_Addr;
    Buffer              : Array [0..30] of Interface_Info;
    i                   : Integer;
Begin
  Result := False;
  SetLength (aNetworkInterfaceList, 0);

  // Startup of old the WinSock
  // WSAStartup ($0101, aWSADataRecord);

  // Startup of WinSock2
  WSAStartup(MAKEWORD(2, 0), aWSADataRecord);

  // Open a socket
  aSocket := Socket (AF_INET, SOCK_STREAM, 0);

  // If impossible to open a socket, not worthy to go any further
  If (aSocket = INVALID_SOCKET) THen Exit;

  Try
    If WSAIoCtl (aSocket, SIO_GET_INTERFACE_LIST, NIL, 0,
                 @Buffer, 1024, @NoOfBytesReturned, NIL, NIL) <> SOCKET_ERROR THen
    Begin
      NoOfInterfaces := NoOfBytesReturned  Div SizeOf (Interface_Info);
      SetLength (aNetworkInterfaceList, NoOfInterfaces);

      // For each of the identified interfaces get:
      For i := 0 to NoOfInterfaces - 1 do
      Begin

        With aNetworkInterfaceList[i] do
        Begin

          // Get the name of the machine
          NameLength := MAX_COMPUTERNAME_LENGTH + 1;
          SetLength (ComputerName, NameLength)  ;
          If Not GetComputerName (PChar (Computername), NameLength) THen ComputerName := '';

          // Get the IP address
          pAddrIP                  := Buffer[i].iiAddress.AddressIn;
          AddrIP                   := string(inet_ntoa (pAddrIP.Sin_Addr));

          // Get the subnet mask
          pAddrSubnetMask          := Buffer[i].iiNetMask.AddressIn;
          SubnetMask               := string(inet_ntoa (pAddrSubnetMask.Sin_Addr));

          // Get the limited broadcast address
          pAddrBroadcast           := Buffer[i].iiBroadCastAddress.AddressIn;
          AddrLimitedBroadcast     := string(inet_ntoa (pAddrBroadcast.Sin_Addr));

          // Calculate the net and the directed broadcast address
          NetAddrDummy.S_addr      := Buffer[i].iiAddress.AddressIn.Sin_Addr.S_Addr;
          NetAddrDummy.S_addr      := NetAddrDummy.S_addr And Buffer[i].iiNetMask.AddressIn.Sin_Addr.S_Addr;
          DirBroadcastDummy.S_addr := NetAddrDummy.S_addr Or Not Buffer[i].iiNetMask.AddressIn.Sin_Addr.S_Addr;

          AddrNet                  := string(inet_ntoa ((NetAddrDummy)));
          AddrDirectedBroadcast    := string(inet_ntoa ((DirBroadcastDummy)));

          // From the evaluation of the Flags we receive more information
          InterfaceFlags           := Buffer[i].iiFlags;

          // Is the network interface up or down ?
          If (InterfaceFlags And IFF_UP) = IFF_UP THen IsInterfaceUp := True
                                                  Else IsInterfaceUp := False;

          // Does the network interface support limited broadcasts ?
          If (InterfaceFlags And IFF_BROADCAST) = IFF_BROADCAST THen BroadcastSupport := True
                                                                Else BroadcastSupport := False;

          // Is the network interface a loopback interface ?
          If (InterfaceFlags And IFF_LOOPBACK) = IFF_LOOPBACK THen IsLoopback := True
                                                              Else IsLoopback := False;
        end;
      end;
    end;
  Except
    //Result := False;
  end;

  // Cleanup the mess
  CloseSocket (aSocket);
  WSACleanUp;
  Result := True;
end;

end.
BroadcastIP := (IP and SubnetMask) or (not SubnetMask);
uses IpHlpApi, IpTypes;

procedure RetrieveLocalAdapterInformation(strings: TStrings);
var
  pAdapterInfo, pTempAdapterInfo: PIP_ADAPTER_INFO;
  AdapterInfo: IP_ADAPTER_INFO;
  BufLen: DWORD;
  Status: DWORD;
  strMAC: String;
  i: Integer;
begin
  strings.Clear;

  BufLen:= sizeof(AdapterInfo);
  pAdapterInfo:= @AdapterInfo;

  Status:= GetAdaptersInfo(nil, BufLen);
  pAdapterInfo:= AllocMem(BufLen);
  try
    Status:= GetAdaptersInfo(pAdapterInfo, BufLen);

    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;
        Dispose(pAdapterInfo);
        Exit;
      end;

    while (pAdapterInfo <> nil) do
      begin
        strings.Add('Description: ' + pAdapterInfo^.Description);
        strings.Add('Name: ' + pAdapterInfo^.AdapterName);

        strMAC := '';
        for I := 0 to pAdapterInfo^.AddressLength - 1 do
            strMAC := strMAC + '-' + IntToHex(pAdapterInfo^.Address[I], 2);

        Delete(strMAC, 1, 1);
        strings.Add('MAC address: ' + strMAC);
        strings.Add('IP address: ' + pAdapterInfo^.IpAddressList.IpAddress.S);
        strings.Add('IP subnet mask: ' + pAdapterInfo^.IpAddressList.IpMask.S);
        strings.Add('Gateway: ' + pAdapterInfo^.GatewayList.IpAddress.S);
        strings.Add('DHCP enabled: ' + IntTOStr(pAdapterInfo^.DhcpEnabled));
        strings.Add('DHCP: ' + pAdapterInfo^.DhcpServer.IpAddress.S);
        strings.Add('Have WINS: ' + BoolToStr(pAdapterInfo^.HaveWins,True));
        strings.Add('Primary WINS: ' + pAdapterInfo^.PrimaryWinsServer.IpAddress.S);
        strings.Add('Secondary WINS: ' + pAdapterInfo^.SecondaryWinsServer.IpAddress.S);

        pTempAdapterInfo := pAdapterInfo;
        pAdapterInfo:= pAdapterInfo^.Next;
      if assigned(pAdapterInfo) then Dispose(pTempAdapterInfo);
    end;
  finally
    Dispose(pAdapterInfo);
  end;
end;
procedure TForm4.RetrieveLocalAdapterInformation;
var
  pAdapterInfo: PIP_ADAPTER_INFO;
  AdapterInfo: IP_ADAPTER_INFO;
  BufLen: DWORD;
  Status: DWORD;
  strMAC: String;
  i: Integer;

  strings: TStrings;
begin
  strings:= Tstringlist.create;
  strings.Clear;

  BufLen:= sizeof(AdapterInfo);
  pAdapterInfo:= @AdapterInfo;

  Status:= GetAdaptersInfo(nil, BufLen);
  pAdapterInfo:= AllocMem(BufLen);
  try
    Status:= GetAdaptersInfo(pAdapterInfo, BufLen);

    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;
        Dispose(pAdapterInfo);
        Exit;
      end;

    while (pAdapterInfo <> nil) do
      begin
      memo1.Lines.Add('');
         memo1.Lines.Add('Description: ------------------------' + pAdapterInfo^.Description);
         memo1.Lines.Add('Name: ' + pAdapterInfo^.AdapterName);

        strMAC := '';
        for I := 0 to pAdapterInfo^.AddressLength - 1 do
            strMAC := strMAC + '-' + IntToHex(pAdapterInfo^.Address[I], 2);

        Delete(strMAC, 1, 1);
         memo1.Lines.Add('MAC address: ' + strMAC);
         memo1.Lines.Add('IP address: ' + pAdapterInfo^.IpAddressList.IpAddress.S);
         memo1.Lines.Add('IP subnet mask: ' + pAdapterInfo^.IpAddressList.IpMask.S);
         memo1.Lines.Add('Gateway: ' + pAdapterInfo^.GatewayList.IpAddress.S);
         memo1.Lines.Add('DHCP enabled: ' + IntTOStr(pAdapterInfo^.DhcpEnabled));
         memo1.Lines.Add('DHCP: ' + pAdapterInfo^.DhcpServer.IpAddress.S);
         memo1.Lines.Add('Have WINS: ' + BoolToStr(pAdapterInfo^.HaveWins,True));
         memo1.Lines.Add('Primary WINS: ' + pAdapterInfo^.PrimaryWinsServer.IpAddress.S);
         memo1.Lines.Add('Secondary WINS: ' + pAdapterInfo^.SecondaryWinsServer.IpAddress.S);

        pAdapterInfo:= pAdapterInfo^.Next;
    end;
  finally
    Dispose(pAdapterInfo);
    strings.free;
  end;
end;

procedure TForm4.Button1Click(Sender: TObject);
begin
   RetrieveLocalAdapterInformation//
end;
procedure TForm4.RetrieveLocalAdapterInformation;
var
  pAdapterInfo: PIP_ADAPTER_INFO; // Linked list of adapters
  pAdapter: PIP_ADAPTER_INFO; // Single adapter
  BufLen: DWORD;
  Status: DWORD;
  strMAC: String;
  i: Integer;
begin
  memo1.Clear;

  // Make an initial call to GetAdaptersInfo to get the necessary size
  // of the linked list
  GetAdaptersInfo(nil, BufLen);
  pAdapterInfo := AllocMem(BufLen);
  try
    Status := GetAdaptersInfo(pAdapterInfo, BufLen);

    if (Status <> ERROR_SUCCESS) then
    begin
      case Status of
        ERROR_NOT_SUPPORTED:
          memo1.Lines.Add('GetAdaptersInfo is not supported by the operating ' +
                      'system running on the local computer.');
        ERROR_NO_DATA:
          memo1.Lines.Add('No network adapter on the local computer.');
      else
        memo1.Lines.Add('GetAdaptersInfo failed with error #' + IntToStr(Status));
      end;

      Exit;
    end;

    pAdapter := pAdapterInfo;

    while (pAdapter <> nil) do
    begin
      memo1.Lines.Add('');
      memo1.Lines.Add('Description: ------------------------' + pAdapter^.Description);
      memo1.Lines.Add('Name: ' + 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);
      memo1.Lines.Add('IP address: ' + pAdapter^.IpAddressList.IpAddress.S);
      memo1.Lines.Add('IP subnet mask: ' + pAdapter^.IpAddressList.IpMask.S);
      memo1.Lines.Add('Gateway: ' + pAdapter^.GatewayList.IpAddress.S);
      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);
      memo1.Lines.Add('Secondary WINS: ' + pAdapter^.SecondaryWinsServer.IpAddress.S);

      pAdapter := pAdapter^.Next;
    end;
  finally
    FreeMem(pAdapterInfo);
  end;
end