Unit1.pas
上传用户:hc3721
上传日期:2021-06-05
资源大小:197k
文件大小:3k
源码类别:

扫描程序

开发平台:

Delphi

  1. unit Unit1;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, DB, ADODB, StdCtrls, ExtCtrls, ScktComp, ComCtrls;
  6. type
  7.   TForm1 = class(TForm)
  8.     ClientSocket1: TClientSocket;
  9.     Timer1: TTimer;
  10.     Memo1: TMemo;
  11.     Label1: TLabel;
  12.     Edit1: TEdit;
  13.     Label2: TLabel;
  14.     Edit2: TEdit;
  15.     Label3: TLabel;
  16.     Edit3: TEdit;
  17.     Button1: TButton;
  18.     ProgressBar1: TProgressBar;
  19.     Label4: TLabel;
  20.     Edit4: TEdit;
  21.     Label5: TLabel;
  22.     Button2: TButton;
  23.     Button3: TButton;
  24.     procedure Button1Click(Sender: TObject);
  25.     procedure Timer1Timer(Sender: TObject);
  26.     procedure ClientSocket1Connect(Sender: TObject;
  27.       Socket: TCustomWinSocket);
  28.     procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
  29.       ErrorEvent: TErrorEvent; var ErrorCode: Integer);
  30.     procedure Button2Click(Sender: TObject);
  31.     procedure Button3Click(Sender: TObject);
  32.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  33.       Shift: TShiftState);
  34.     procedure FormCreate(Sender: TObject);
  35.   private
  36.     { Private declarations }
  37.   public
  38.     { Public declarations }
  39.   end;
  40. var
  41.   Form1: TForm1;
  42.   i:Integer;
  43. implementation
  44. {$R *.dfm}
  45. procedure TForm1.Button1Click(Sender: TObject);
  46. begin
  47. i:=StrToInt(Edit2.Text);
  48. Timer1.Interval:=StrToInt(Edit4.Text);//自行填写扫描时间间隔
  49. Timer1.Enabled:=True;
  50. ProgressBar1.Min:=StrToInt(Edit2.Text); //设置进度条最小值
  51. ProgressBar1.Max:=StrToInt(Edit3.Text)-StrToInt(Edit2.Text);//进度条最大值
  52. end;
  53. procedure TForm1.Timer1Timer(Sender: TObject);
  54. begin
  55.  if i=StrToInt(Edit3.Text)  then  //当值为最大时,算出计时时间
  56.  Timer1.Enabled:=False
  57.  else
  58.  ClientSocket1.Port:=i;  //控件的端口
  59.  ClientSocket1.Address:=Edit1.Text; //控件连接的IP地址
  60.  ClientSocket1.Open; //连接IP,执行控件
  61.  i:=i+1; //变量自加一,便于扫描下一个端口
  62.  ProgressBar1.StepBy(1);  //进度条加1
  63. end;
  64. //端口扫描连接
  65. procedure TForm1.ClientSocket1Connect(Sender: TObject;
  66.   Socket: TCustomWinSocket);
  67. begin
  68. Memo1.Lines.Add('扫描到端口:'+inttostr(i-1)); //连接成功后输出端口
  69. ClientSocket1.Close;
  70. end;
  71. procedure TForm1.ClientSocket1Error(Sender: TObject;
  72.   Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  73.   var ErrorCode: Integer);
  74. begin
  75. ErrorCode:=0;  //容错代码
  76. end;
  77. procedure TForm1.Button2Click(Sender: TObject);
  78. begin
  79.  ClientSocket1.Active:=False;
  80.  Timer1.Enabled:=False;
  81.   ProgressBar1.Max:=0;
  82. end;
  83. procedure TForm1.Button3Click(Sender: TObject);
  84. begin
  85. Close;
  86. end;
  87. procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  88.   Shift: TShiftState);
  89. begin
  90.   if Key = 27 then
  91.     Close;
  92. end;
  93. procedure TForm1.FormCreate(Sender: TObject);
  94. begin
  95. Form1.KeyPreview:=True;
  96. end;
  97. end.