Einzelnen Beitrag anzeigen

Astat

Registriert seit: 2. Dez 2009
Ort: München
320 Beiträge
 
Lazarus
 
#2

Re: Netzwerkverbindung Info auslesen

  Alt 25. Feb 2010, 21:04
Hallo Pluto, IpHelper API sollte die gewünschten Infos liefern.

Delphi-Quellcode:

uses
  windows,
  SysUtils;

const
  MAX_INTERFACE_NAME_LEN = 256;
  MAXLEN_PHYSADDR = 8;
  MAXLEN_IFDESCR = 256;
  ANY_SIZE = 1;

type
  PTMibIfRow = ^TMibIfRow;
  TMibIfRow = packed record
    wszName : array[1..MAX_INTERFACE_NAME_LEN] of WCHAR;
    dwIndex : DWORD;
    dwType : DWORD;
    dwMTU : DWORD;
    dwSpeed : DWORD;
    dwPhysAddrLen : DWORD;
    bPhysAddr : array[1..MAXLEN_PHYSADDR] of byte;
    dwAdminStatus : DWORD;
    dwOperStatus : DWORD;
    dwLastChange : DWORD;
    dwInOctets : DWORD;
    dwInUcastPkts : DWORD;
    dwInNUCastPkts : DWORD;
    dwInDiscards : DWORD;
    dwInErrors : DWORD;
    dwInUnknownProtos : DWORD;
    dwOutOctets : DWORD;
    dwOutUCastPkts : DWORD;
    dwOutNUCastPkts : DWORD;
    dwOutDiscards : DWORD;
    dwOutErrors : DWORD;
    dwOutQLen : DWORD;
    dwDescrLen : DWORD;
    bDescr : array[1..MAXLEN_IFDESCR] of char;
  end;

  TMIBIfArray = array of TMIBIFRow;

  PTMibIfTable = ^TMIBIfTable;
  TMibIfTable = packed record
    dwNumEntries : DWORD;
    Table : array[0..ANY_SIZE - 1] of TMibIfRow;
  end;

function GetIfTable(pIfTable: PTMibIfTable; pdwSize: PULONG;
  bOrder: boolean): DWORD; stdCall; external 'IPHLPAPI.DLL';

procedure GetIfTableMIB(var MIBIfArray: TMIBIfArray);
var
  i, Error, TableSize: integer;
  pBuf: PChar;
  NumEntries: DWORD;
begin
  TableSize := 0;
  NumEntries := 0;
  pBuf := nil;
  Error := GetIfTable(PTMibIfTable(pBuf), @TableSize, false);
  if Error <> ERROR_INSUFFICIENT_BUFFER then EXIT;
  GetMem(pBuf, TableSize);
  Error := GetIfTable(PTMibIfTable(pBuf), @TableSize, false);
  if Error = NO_ERROR then begin
    NumEntries := PTMibIfTable(pBuf)^.dwNumEntries;
    if NumEntries > 0 then begin
      SetLength(MIBIfArray, NumEntries);
      inc(pBuf, SizeOf(NumEntries));
      for i := 0 to pred(NumEntries) do begin
        MIBIfArray[i] := PTMibIfRow(pBuf)^;
        inc(pBuf, SizeOf(TMIBIfRow));
      end;
    end
  end;
  dec(pBuf, SizeOf(DWORD) + NumEntries * SizeOf(TMIBIfRow));
  FreeMem(pBuf);
end;

function GetAdapterInfos: string;
var
  MibArr : TMIBIfArray;
  i : integer;
  Descr: string;
begin
  GetIfTableMIB(MibArr);
  if Length(MibArr) > 0 then begin
    for i := Low(MIBArr) to High(MIBArr) do begin
      SetLength(Descr, Pred(MIBArr[i].dwDescrLen));
      Move(MIBArr[i].bDescr, Descr[1], pred(MIBArr[i].dwDescrLen));
      result := result + Trim(Descr) + #13#10;
    end;
  end;
end;

begin
  writeln(GetAdapterInfos);
  readln;
end.

lg. Astat
Lanthan Astat
06810110811210410503210511511603209711003210010110 9032084097103
03211611111604403209711003210010110903210010510103 2108101116122
11610103209010110510810103206711110010103210511003 2068101108112
10410503210310111509910411410510109810111003211910 5114100046
  Mit Zitat antworten Zitat