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.