Unit1.pas
上传用户:hc3721
上传日期:2021-06-05
资源大小:197k
文件大小:3k
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, DB, ADODB, StdCtrls, ExtCtrls, ScktComp, ComCtrls;
- type
- TForm1 = class(TForm)
- ClientSocket1: TClientSocket;
- Timer1: TTimer;
- Memo1: TMemo;
- Label1: TLabel;
- Edit1: TEdit;
- Label2: TLabel;
- Edit2: TEdit;
- Label3: TLabel;
- Edit3: TEdit;
- Button1: TButton;
- ProgressBar1: TProgressBar;
- Label4: TLabel;
- Edit4: TEdit;
- Label5: TLabel;
- Button2: TButton;
- Button3: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure ClientSocket1Connect(Sender: TObject;
- Socket: TCustomWinSocket);
- procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
- ErrorEvent: TErrorEvent; var ErrorCode: Integer);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- i:Integer;
- implementation
- {$R *.dfm}
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- i:=StrToInt(Edit2.Text);
- Timer1.Interval:=StrToInt(Edit4.Text);//自行填写扫描时间间隔
- Timer1.Enabled:=True;
- ProgressBar1.Min:=StrToInt(Edit2.Text); //设置进度条最小值
- ProgressBar1.Max:=StrToInt(Edit3.Text)-StrToInt(Edit2.Text);//进度条最大值
- end;
- procedure TForm1.Timer1Timer(Sender: TObject);
- begin
- if i=StrToInt(Edit3.Text) then //当值为最大时,算出计时时间
- Timer1.Enabled:=False
- else
- ClientSocket1.Port:=i; //控件的端口
- ClientSocket1.Address:=Edit1.Text; //控件连接的IP地址
- ClientSocket1.Open; //连接IP,执行控件
- i:=i+1; //变量自加一,便于扫描下一个端口
- ProgressBar1.StepBy(1); //进度条加1
- end;
- //端口扫描连接
- procedure TForm1.ClientSocket1Connect(Sender: TObject;
- Socket: TCustomWinSocket);
- begin
- Memo1.Lines.Add('扫描到端口:'+inttostr(i-1)); //连接成功后输出端口
- ClientSocket1.Close;
- end;
- procedure TForm1.ClientSocket1Error(Sender: TObject;
- Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
- var ErrorCode: Integer);
- begin
- ErrorCode:=0; //容错代码
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- ClientSocket1.Active:=False;
- Timer1.Enabled:=False;
- ProgressBar1.Max:=0;
- end;
- procedure TForm1.Button3Click(Sender: TObject);
- begin
- Close;
- end;
- procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- if Key = 27 then
- Close;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Form1.KeyPreview:=True;
- end;
- end.