端口扫描,用delphi如何做?(200分)

  • 主题发起人 主题发起人 aerobull
  • 开始时间 开始时间

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,如果成功肯定就是打开的了

 
smilboy,:
有这么容易吗?
我要的是"最好不会在对方计算机留下痕迹。"
 
那你就要自己从低层写了
建议看一下TCP/IP的三次握手
就是说每次连接要有三次握手才能成功。
你可以只握一次手
不过实现起来就困难了
我只知道原理
建议你到http://www.s8s8.net去看看
或者http://www.honker.com
 
你们说的低层是指那个范围 ,api,winsock,
我也洗耳恭听
 
你们说的根本上就是不对的,
什么三次中的一次,这是不可能的,
最起码也要三次中的前两次,
比如syn/fin,
如果你连socket api,raw socket等都不懂,
我劝你不要想了,
并且,如果你是使用的98,想都不要想,
因为98根本就不支持raw socket,
就算是在2000下面,一般也要写一个驱动程序,
这个不是一个简单的事情的。
如果你看得懂nmapnt你可以看看,
那就是一个典型的列子,有原始程序。

更何况,端口扫描能够起什么作用呢?
我是不认为能够怎么样的。
 
老板呢?结束话题吧!
 
下面这个是在linux下得实现方法,(转载)
因为windows得特性,如果想直接实现syn是不可能的。
需要winpacp驱动。
 
接受答案了.
 
后退
顶部