📄 pingthread2.~pas
字号:
unit PingThread2;
interface
uses
Classes,stdctrls,Sysutils,scktcomp,checklst;
type
PingIP2 = class(TThread)
UseCSockt:TClientSocket;
procedure InConnect(Sender: TObject;Socket: TCustomWinSocket);
procedure InError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure InDisconnect(Sender: TObject;Socket: TCustomWinSocket);
private
{ Private declarations }
protected
procedure Execute; override;
Procedure onPingTerminate(sender:TObject);
public
RV:integer;
constructor Create(ShowLabel:TLabel);
Procedure ConnectIP(IPaddr:String;DPort:Integer;SaveIP:TCheckListBox);
Procedure InsertIP;
end;
Var
InIPAddr:String;
InSaveIP:TCheckListBox;
InPort:Integer;
InLabel:TLabel;
implementation
Constructor PingIP2.Create(ShowLabel:TLabel);
begin
InLabel:=ShowLabel;
UseCSockt:=TClientSocket.Create(nil);
UseCSockt.ClientType:=ctNonBlocking;
UseCSockt.OnError:=InError;
UseCSockt.OnConnect:=InConnect;
UseCSockt.OnDisconnect:=InDisconnect;
Self.OnTerminate:=self.onPingTerminate;
inherited Create(False);
end;
Procedure PingIP2.ConnectIP(IPaddr:String;DPort:Integer;SaveIP:TCheckListBox);
begin
self.RV:=1;
InSaveIP:=SaveIP;
InIPAddr:=IPAddr;InPort:=DPort;
UseCSockt.Close;
UseCSockt.Address:=InIPAddr;
UseCsockt.Port:=InPort;
Synchronize(InsertIP);
self.RV:=0;
self.DoTerminate;
self.Terminate;
self:=nil;
end;
Procedure PingIP2.InsertIP;
begin
try
InLabel.Caption:='线程'+IntToStr(self.ThreadID)+'正在对目标主机:'+UseCSockt.Address+'->扫描端口:'+IntToStr(UseCSockt.Port)
+'进行中... ... .'+UseCSockt.Host;
UseCSockt.Open;
except
UseCSockt.Close;
UseCSockt.Address:='';
Self.ReturnValue:=18;
self.Terminate;
self:=nil;
end;
UseCSockt.Close;
self.DoTerminate;
self.Terminate;
self:=nil;
end;
procedure PingIP2.InConnect(Sender: TObject;Socket: TCustomWinSocket);
Begin
InLabel.Caption:='搜索线程'+IntToStr(self.ThreadID)+'正在连接目标主机:'+InIPAddr+':'+IntToStr(InPort)+'... .. .';
InSaveIP.Items.Insert(0,Socket.RemoteAddress+'='+Socket.RemoteHost+'端口:'+IntToStr(socket.RemotePort));
Socket.Close;
UseCSockt.Close;
UseCSockt.Address:='';
Self.ReturnValue:=18;
self.Terminate;
self:=nil;
end;
procedure PingIP2.InError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
ErrorCode:=0;
Socket.Close;
UseCSockt.Close;
UseCSockt.Address:='';
Self.ReturnValue:=18;
self.Terminate;
self:=nil;
end;
procedure PingIP2.InDisconnect(Sender: TObject;Socket: TCustomWinSocket);
Begin
if Socket.RemoteAddress<>'' then
begin
InLabel.Caption:='返回线程'+IntToStr(self.ThreadID)+'连接目标主机:'+InIPAddr+'::'+IntToStr(InPort)+'---已断开。';
end else InLabel.Caption:='返回线程'+IntToStr(self.ThreadID)+'搜索目标主机:'+InIPAddr+'::'+IntToStr(InPort)+'---探测失败已断开。';
UseCSockt.Close;
UseCSockt.Address:='';
Self.ReturnValue:=18;
self.Terminate;
self:=nil;
end;
procedure PingIP2.onPingTerminate(Sender:TObject);
begin
self.RV:=0;
Self.ReturnValue:=18;
self.Terminate;
self:=nil;
end;
procedure PingIP2.Execute;
begin
self.RV:=0;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -