const
ANY_SIZE = 1;
type
MIB_TCPROW_OWNER_PID =
packed record
dwState: DWORD;
dwLocalAddr: DWORD;
dwLocalPort: DWORD;
dwRemoteAddr: DWORD;
dwRemotePort: DWORD;
dwOwningPid: DWORD;
end;
PMIB_TCPROW_OWNER_PID = ^MIB_TCPROW_OWNER_PID;
type
MIB_TCPTABLE_OWNER_PID =
packed record
dwNumEntries: DWord;
table:
array [0..ANY_SIZE - 1]
of MIB_TCPROW_OWNER_PID ;
end;
PMIB_TCPTABLE_OWNER_PID = ^MIB_TCPTABLE_OWNER_PID;
const
TCP_TABLE_OWNER_PID_ALL = 5;
AF_INET = 0;
type
TCP_TABLE_CLASS = Integer;
ULONG = Longword;
function GetExtendedTcpTable(pTcpTable: Pointer; dwSize: PDWORD; bOrder: BOOL;
lAf: ULONG; TableClass: TCP_TABLE_CLASS; Reserved: ULONG): DWord;
stdcall;
external '
iphlpapi.dll'
name '
GetExtendedTcpTable';
// TCP Table + PID
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
pTcpTable: PMIB_TCPTABLE_OWNER_PID;
dwSize: PDWord;
Res: Dword;
I: Integer;
begin
New(pTcpTable);
New(dwSize);
dwSize^:=SizeOf(MIB_TCPTABLE_OWNER_PID);
Res := GetExtendedTcpTable(pTcpTable, dwSize, False, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0);
// False = unsortiert
if Res<>NO_ERROR
then
raise Exception.Create(SysErrorMessage(Res));
for I := 0
to pTcpTable.dwNumEntries
do
writeln( IntToStr(pTcpTable.table[I].dwOwningPid) );
dispose(dwSize);
dispose(pTcpTable);
end;
end.