
06.07.2025, 21:55
|
Новичок
|
|
Регистрация: 18.03.2009
Сообщения: 82
Репутация: 10
|
|
сортировка
добавил: PID :=1234;
if dwOwningPid = PID then
может что то упустил
Код:
procedure TConnectionListener.ListOpenTCPConnections;
var
TcpTable: PMIB_TCPTABLE_OWNER_PID;
TableSize,PID: DWORD;
i: Integer;
begin
PID :=1234;// strtoint(form1.edit1.text);
TableSize := 0;
// First call to get the required buffer size
GetExtendedTcpTable(nil, TableSize, True, AF_INET, {TCP_TABLE_BASIC_CONNECTIONS} TCP_TABLE_OWNER_PID_ALL, 0);
// Allocate memory for the table
GetMem(TcpTable, TableSize);
try
// Retrieve the TCP table
if GetExtendedTcpTable(TcpTable, TableSize, True, AF_INET, {TCP_TABLE_BASIC_CONNECTIONS} TCP_TABLE_OWNER_PID_ALL, 0) = NO_ERROR then
begin
SetLength(FIpTable,TcpTable.dwNumEntries);
for i := 0 to TcpTable.dwNumEntries - 1 do
begin
with TcpTable.Table[i] do
begin
if dwOwningPid = PID then
begin
FIpTable[i].LocalAddr := Format('%d.%d.%d.%d:%d', [
dwLocalAddr and $FF,
(dwLocalAddr shr 8) and $FF,
(dwLocalAddr shr 16) and $FF,
(dwLocalAddr shr 24) and $FF,
ntohs(dwLocalPort)
]);
FIpTable[i].RemoteAddr := Format('%d.%d.%d.%d:%d', [
dwRemoteAddr and $FF,
(dwRemoteAddr shr 8) and $FF,
(dwRemoteAddr shr 16) and $FF,
(dwRemoteAddr shr 24) and $FF,
ntohs(dwRemotePort)
]);
end;
end;
end;
end
else
Begin
SetLength(FIpTable,1);
FIpTable[0].LocalAddr := 'Error';
FIpTable[0].RemoteAddr := 'Error';
End;
finally
FreeMem(TcpTable);
end;
end;
|