S
smilboy
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ScktComp;
type
TForm1 = class(TForm)
Bevel1: TBevel;
Bevel2: TBevel;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Label3: TLabel;
Bevel3: TBevel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Bevel4: TBevel;
Edit4: TEdit;
ListBox1: TListBox;
ClientSock1: TClientSocket;
procedure Button1Click(Sender: TObject);
procedure ClientSock1Connect(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSock1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
portno:integer;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
button1.enabled:=false;
edit1.enabled:=false;
edit2.enabled:=false;
edit3.enabled:=false;
edit4.enabled:=false;
button2.enabled:=true;
portno:=strtoint(edit2.text);
ClientSock1.address:=edit1.text;
ClientSock1.port:=portno;
ClientSock1.active:=true;
end;
procedure TForm1.ClientSock1Connect(Sender: TObject; Socket: TCustomWinSocket);
label son;
begin
listbox1.items.add('找到打开端口 : '+inttostr(portno));
ClientSock1.active:=false;
portno:=portno+1;
if portno > strtoint(edit3.text) then goto son else
ClientSock1.address:=edit1.text;
ClientSock1.port:=portno;
ClientSock1.active:=true;
son:
end;
procedure TForm1.ClientSock1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
label son;
begin
errorcode:=0;
edit4.text:='扫描端口 : '+inttostr(portno);
ClientSock1.active:=false;
portno:=portno+1;
if portno > strtoint(edit3.text) then goto son else
ClientSock1.address:=edit1.text;
ClientSock1.port:=portno;
ClientSock1.active:=true;
son:
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
portno:=strtoint(edit3.text);
button1.enabled:=true;
edit1.enabled:=true;
edit2.enabled:=true;
edit3.enabled:=true;
edit4.enabled:=true;
button2.enabled:=false;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
edit4.text:='';
listbox1.items.clear;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ClientSock1.active:=false;
end;
end.
===========================================
object Form1: TForm1
Left = 323
Top = 248
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = '端口扫描器'
ClientHeight = 275
ClientWidth = 215
Color = clBtnFace
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 12
object Bevel1: TBevel
Left = 0
Top = 0
Width = 215
Height = 275
Align = alClient
end
object Bevel2: TBevel
Left = 7
Top = 7
Width = 202
Height = 52
end
object Label1: TLabel
Left = 13
Top = 20
Width = 42
Height = 12
Caption = 'IP 地址'
end
object Label2: TLabel
Left = 13
Top = 39
Width = 48
Height = 12
Caption = '开始端口'
end
object Label3: TLabel
Left = 117
Top = 39
Width = 48
Height = 12
Caption = '停止端口'
end
object Bevel3: TBevel
Left = 7
Top = 65
Width = 202
Height = 59
end
object Bevel4: TBevel
Left = 7
Top = 130
Width = 202
Height = 137
end
object Edit1: TEdit
Left = 72
Top = 13
Width = 130
Height = 20
TabOrder = 0
Text = '127.0.0.1'
end
object Edit2: TEdit
Left = 72
Top = 33
Width = 33
Height = 20
TabOrder = 1
Text = '1'
end
object Edit3: TEdit
Left = 169
Top = 33
Width = 33
Height = 20
TabOrder = 2
Text = '65535'
end
object Button1: TButton
Left = 13
Top = 72
Width = 189
Height = 20
Caption = '开始'
TabOrder = 3
OnClick = Button1Click
end
object Button2: TButton
Left = 37
Top = 98
Width = 61
Height = 20
Caption = '停止'
Enabled = False
TabOrder = 4
OnClick = Button2Click
end
object Button3: TButton
Left = 110
Top = 98
Width = 61
Height = 20
Caption = '清除'
TabOrder = 5
OnClick = Button3Click
end
object Edit4: TEdit
Left = 13
Top = 137
Width = 189
Height = 20
TabOrder = 6
end
object ListBox1: TListBox
Left = 13
Top = 163
Width = 189
Height = 98
ItemHeight = 12
TabOrder = 7
end
object ClientSock1: TClientSocket
Active = False
ClientType = ctNonBlocking
Port = 0
OnConnect = ClientSock1Connect
OnError = ClientSock1Error
Left = 24
Top = 216
end
end
窗体文件和单元都贴了上来
你剪下来就好了
基本原理就是一个一个的去connect,如果成功肯定就是打开的了