type
TSetTcpEntry=
Function(pTcpRow: PMIB_TCPROW): DWORD;
stdcall;
type
MIB_TCPROW =
packed record
dwState,
dwLocalAddr,
dwLocalPort,
dwRemoteAddr,
dwRemotePort: DWORD;
end;
PMIB_TCPROW = ^MIB_TCPROW;
function CloseTCPConnection(pTcpRow: PMIB_TCPROW): Boolean;
begin
pTcpRow.dwState := MIB_TCP_STATE_DELETE_TCB;
if pSetTcpEntry(pTcpRow) = NO_ERROR
then
Result := True
else
Result := False;
end;
function TForm1.GetTCPRow: PMIB_TCPROW;
var
I, X: Integer;
S, sLocalIp, sRemoteIp:
String;
iLocalPort, iRemotePort: Cardinal;
begin
if ListView1.ItemIndex = -1
then exit;
S := ListView1.Items.Item[ListView1.ItemIndex].SubItems[1];
X := Pos('
:', S);
sLocalIp := Copy(S, 1, X-1);
iLocalPort := StrToInt( Copy(S, X+1, Length(S)) );
S := ListView1.Items.Item[ListView1.ItemIndex].SubItems[2];
X := Pos('
:', S);
sRemoteIp := Copy(S, 1, X-1);
iRemotePort := StrToInt( Copy(S, X+1, Length(S)) );
Result.dwLocalAddr := GetAddress(PAnsiChar(sLocalIp));
// und hier kommt die AV
Result.dwLocalPort := GetPort(iLocalPort);
// functionen wie oben geschrieben
Result.dwRemoteAddr := GetAddress(PChar(sRemoteIp));
Result.dwRemotePort := GetPort(iRemotePort);
end;
procedure TForm1.Schliessen1Click(Sender: TObject);
begin
if CloseTCPConnection(GetTCPRow)
then
showmessage('
Verbindung geschlossen')
else
showmessage('
Fehler');
end;