帮助看一代码:扫描本机已经打开的端口 ( 积分: 19 )

  • 主题发起人 主题发起人 ykjt
  • 开始时间 开始时间
Y

ykjt

Unregistered / Unconfirmed
GUEST, unregistred user!
Unit Unit1;

Interface

Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp;

Type
TForm1 = Class(TForm)
ListBox1: TListBox;
Button1: TButton;
ServerSocket1: TServerSocket;
Procedure FormCreate(Sender: TObject);
Procedure Button1Click(Sender: TObject);
Procedure FormDestroy(Sender: TObject);
PRIVATE
{ Private declarations }
PUBLIC
{ Public declarations }
End;

Var
Form1: TForm1;


Implementation

{$R *.dfm}

Procedure TForm1.FormCreate(Sender: TObject);

Begin
ServerSocket1 := TServerSocket.Create(self);
ServerSocket1.Active := True;
End;

Procedure TForm1.Button1Click(Sender: TObject);
Var
i: Integer;
Begin
ListBox1.Items.Clear;
For i := 0 To 1000 Do
Begin
ServerSocket1.Close;
ServerSocket1.Port := i;
Try
ServerSocket1.Open;
Except
ListBox1.Items.Add(IntToStr(i) + '端口已经打开');
End;
End;

End;

Procedure TForm1.FormDestroy(Sender: TObject);
Begin
ServerSocket1.Free;
End;

End.

运行时错误:通常每个套接字地址(协议/网络地址/端口)只允许使用一次
 
Unit Unit1;

Interface

Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp;

Type
TForm1 = Class(TForm)
ListBox1: TListBox;
Button1: TButton;
ServerSocket1: TServerSocket;
Procedure FormCreate(Sender: TObject);
Procedure Button1Click(Sender: TObject);
Procedure FormDestroy(Sender: TObject);
PRIVATE
{ Private declarations }
PUBLIC
{ Public declarations }
End;

Var
Form1: TForm1;


Implementation

{$R *.dfm}

Procedure TForm1.FormCreate(Sender: TObject);

Begin
ServerSocket1 := TServerSocket.Create(self);
ServerSocket1.Active := True;
End;

Procedure TForm1.Button1Click(Sender: TObject);
Var
i: Integer;
Begin
ListBox1.Items.Clear;
For i := 0 To 1000 Do
Begin
ServerSocket1.Close;
ServerSocket1.Port := i;
Try
ServerSocket1.Open;
Except
ListBox1.Items.Add(IntToStr(i) + '端口已经打开');
End;
End;

End;

Procedure TForm1.FormDestroy(Sender: TObject);
Begin
ServerSocket1.Free;
End;

End.

运行时错误:通常每个套接字地址(协议/网络地址/端口)只允许使用一次
 
端口号是字符型的吧,好像不是整型的。
 
用clientsocket 比较好
clientsocket.remove:='127.0.0.1';
clientsocket.port:=
clientsocket .open;
if clientsocket .active then ..........
else .....................
 
用clientsocket 比较好
=================
改用clientsocket后,提示:no address apecified

ClientSocket1:=TClientSocket.Create(self);
ClientSocket1.Active:=True;
ClientSocket1.Address:='127.0.0.1';
也不行
 

Similar threads

I
回复
0
查看
763
import
I
I
回复
0
查看
566
import
I
后退
顶部