![]() |
Probleme mit netstat
hallo liebe Delphigemeinde!
Hab mal wieder ein Problem... Ich will mit einem Timer jede Sekunde oder so den internet verkehr prüfen, ob dort eine bestimmte .exe dabei ist... also überprüfe ich das mit der unit DosCommand, die ich hier iwo gedownloadet habe und habe folgenen code
Delphi-Quellcode:
so das funktioniert auch alles nur manchmal
var
cmd : TDosCommand; sl: TStringList; i,a:integer; begin i:=0; a:=0; cmd:= TDosCommand.Create(nil); sl := TStringList.Create; cmd.OutputLines:=sl; cmd.InputToOutput:=true; cmd.CommandLine:='netstat -b'; cmd.Execute; while cmd.IsRunning do application.ProcessMessages; FreeAndNil(cmd); i:=Pos('[blabla.exe]', sl.Text); //durchsuche den Text nach der .exe a:=Pos('12345', sl.Text); //durchsuche sicherheitshalber den text auch nach dem Port if (i=0) or (a=0) then begin showmessage('ACHTUNG'); end; sl.Free; end; 1. hängt sich der PC iwie auf und öffnet ganz oft netstat.exe aber schließt diese nicht mehr... (bei einem anderen PC kommt das oft vor) 2. hat das gesuchte programm, dass ins internet zugreift, manchmal etwas andere probleme, bei denen zwar das programm nicht mehr arbeitet aber dennoch gestartet, ins internet zugreift und den selben Port benutzt... also kennt vllt jemand eine möglichkeit, mein vorhaben zu verwirklichen ohne andere .exe zu öffnen und was vllt bisschen genauer arbeitet? vielen dank schonmal für eure hilfe im vorraus :) mfg Innos |
Re: Probleme mit netstat
hab hier so ein Tutorial...
![]() das verstehe ich aber nicht so recht :( habe des mal alles eingefügt und dann kamen einige fehler-.- bin mir nicht mal sicher wie man genau nun diese "iphlpapi.dll" einbindet... jedenfalls startet das programm aber es steht in dem ListView nur "TCP" da und das mehrere male :wall: mein code
Delphi-Quellcode:
es muss ja nicht gleich die lösung sein aber bitte helft mir das n bissl zu verstehn^^
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls; type TForm1 = class(TForm) Button1: TButton; ListView1: TListView; function getIP(var addr) : string; procedure holeTcpTable; function getPort(var addr) : string; function getTCPState(status : integer) : string; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation var cCode: Word; L : record // L ist ein Record für das Auslesen der Werte cbRequired : Longint; // wird gebraucht, um die benötigte Buffer-Größe zu ermitteln nStructSize : LongInt; // Größe der Struktur tmp : String; end; type TMIB_TCPROW = record dwState : LongInt; //state of the connection dwLocalAddr : array[0..3]of byte ; //address on local computer dwLocalPort : array[0..3]of byte ; //port number on local computer dwRemoteAddr : array[0..3]of byte ; //address on remote computer dwRemotePort : array[0..3]of byte ; //port number on remote computer end; type TMIB_TCPTABLE = record dwNumEntries : Longint; //number of entries in the table table : array [0..100] of TMIB_TCPROW; //array of TCP connections end; function GetTcpTable (pTcpTable: Pointer; var pdwSize : Longint; bOrder : Longint): Longint;stdcall; stdcall; external 'iphlpapi' name 'GetTcpTable'; Const MIB_TCP_STATE_CLOSED = 0; Const MIB_TCP_STATE_LISTEN = 1; Const MIB_TCP_STATE_SYN_SENT = 2; Const MIB_TCP_STATE_SYN_RCVD = 3; Const MIB_TCP_STATE_ESTAB = 4; Const MIB_TCP_STATE_FIN_WAIT1 = 5; Const MIB_TCP_STATE_FIN_WAIT2 = 6; Const MIB_TCP_STATE_CLOSE_WAIT = 7; Const MIB_TCP_STATE_CLOSING = 8; Const MIB_TCP_STATE_LAST_ACK = 9; Const MIB_TCP_STATE_TIME_WAIT = 10; Const MIB_TCP_STATE_DELETE_TCB = 11; {$R *.dfm} procedure TForm1.holeTcpTable; var liItem : Tlistitem; var liste : TListitems; var subitem : TStringlist; var m_pTcpTable : ^TMIB_TCPTABLE; var i : integer; begin Liste := Tlistitems.Create(listview1); listview1.Items.Clear; m_pTcpTable := nil; ZeroMemory(@L,sizeof(L)); cCode := GetTcpTable(m_pTcpTable,L.cbRequired,0); GetMem(m_pTcpTable,L.cbRequired); ZeroMemory (m_pTcpTable,L.cbRequired); cCode := GetTcpTable(m_pTcpTable,L.cbRequired,0); // cCode als global vereinbarte Variable vom Type Word, um den Rückgabewert der API-Funktion zu erhalten if cCode <> ERROR_SUCCESS then begin showmessage ('Fehler bei GetTcpTable ' + inttostr(cCode)); end else begin for i:= 0 to m_pTcpTable.dwNumEntries-1 do begin showmessage('A'); liItem := liste.Add; subitem := TStringlist.Create; subitem.Add(getIp(m_pTcpTable^.table[i].dwLocalAddr)); liItem.SubItems:=subitem; liItem.Caption := 'TCP'; liItem.SubItems.Add (getPort(m_pTcpTable^.table[i].dwLocalPort)); liItem.SubItems.Add (getIp(m_pTcpTable^.table[i].dwRemoteAddr)); if (m_pTcpTable^.table[i].dwState-1 <> MIB_TCP_STATE_LISTEN) then begin showmessage('B'); liItem.SubItems.Add (getPort(m_pTcpTable^.table[i].dwRemotePort)); end else begin showmessage('C'); liItem.SubItems.Add ('0'); end; showmessage('D'); liItem.SubItems.Add (getTCPState(m_pTcpTable^.table[i].dwState)); end; end; end; // ein paar Funktionen zur Formatierung... function TForm1.getIP(var addr) : string; var daten : array[0..3] of byte absolute addr; begin result := Format('%d.%d.%d.%d',[Daten[0],daten[1],Daten[2],Daten[3]]) end; function TForm1.getPort(var addr) : string; var daten : array[0..3] of byte absolute addr; begin result := Format('%d',[Daten[0]*256+daten[1]]); end; function TForm1.getTCPState(status : integer) : string; begin status := status -1 ; if status = 0 then result := 'closed'; if status = 1 then result := 'listen'; if status = 2 then result := 'SYN_Sent'; if status = 3 then result := 'SYN_Rcvd'; if status = 4 then result := 'established'; if status = 5 then result := 'Fin wait 1'; if status = 6 then result := 'Fin wait 2'; if status = 7 then result := 'Close wait'; if status = 8 then result := 'closing'; if status = 9 then result := 'last Ack.'; if status = 10 then result := 'time wait'; if status = 11 then result := 'delete TCB'; end; procedure TForm1.Button1Click(Sender: TObject); begin holeTcpTable; end; end. zB was ist: '%d.%d.%d.%d' :wiejetzt: mfg Innos |
Re: Probleme mit netstat
Schau mal in Hilfe unter
![]() ![]() /EDIT: Zitat:
|
Re: Probleme mit netstat
ja gut^^ ich bin anfäanger :D hab vorher nie mit ListView gearbeitet sry jedenfalls war es das richtige!!!
THX :thumb: :thumb: weißt gar nicht wie sehr du mir geholfen hast xD |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:56 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz