this slowpoke moves

Get Gateway IP

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';

Beispiel :
procedure TForm1.Button1Click(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;
        ListBox1.Clear;
        repeat

        ShowMessage(trim(pAdapterWork.AdapterName)); //  interne Name

          iasWork := pAdapterWork.GatewayList;
          while iasWork.Next <> nil do
          begin
            ListBox1.Items.Add(trim(iasWork.IpAddress.acString));
            iasWork := iasWork.Next^;
          end;
          ListBox1.Items.Add(trim(iasWork.IpAddress.acString));
          pAdapterWork := pAdapterWork.Next;
        until pAdapterWork = nil;
        if ListBox1.Items.Count > 0 then
        begin
          ListBox1.ItemIndex := 0;
        end;
      end;
    finally
      FreeMem(pAdapterList,dwLen);
    end;
  end;
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate