Thema: Delphi portscanner

Einzelnen Beitrag anzeigen

bonanza

Registriert seit: 13. Sep 2005
134 Beiträge
 
RAD-Studio 2009 Arc
 
#1

portscanner

  Alt 12. Feb 2006, 17:31
das soll ein portscanner werden ^^
doch macht er einen dummen fehler beim compilieren in der Project1.DPR...

Komplettes Projekt siehe anhang...
wäre super nett, wenn jemand sagen könnte, wo der fehler liegt, und wie ich ihn behebn könnte..

Hier der Code:
Code:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Ed_Ip1: TEdit;
    Ed_Ip2: TEdit;
    Ed_Port: TEdit;
    Bt_Start: TButton;
    Me_Output: TMemo;
    Bt_Stop: TButton;
    ClientSocket: TClientSocket;
    gauge1: TProgressBar;
    procedure ClientSocketConnect(Sender: TObject; Socket: TCustomWinSocket);
    procedure ClientSocketError(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure Bt_StartClick(Sender: TObject);
    procedure Bt_StopClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  over,over2:Boolean;
  z,i1,i2,i3,scanips:Integer; // IP-Nr. 127.i1.i2.i3
  var Ipnr1, Ipnr2: array of integer; // Array of Start and Stop IP
implementation

{$R *.dfm}

procedure Scan(ClientSocket: TClientSocket; Me_Output: TMemo;
Bt_Start,Bt_Stop: TButton; Gauge1: TProgressBar);
var strtemp1,iptemp: String;
var perc_real,progr_real:Real;
var progr_int,error:Integer;
begin

  if (ipnr1[0] >= ipnr2[0]) and (i1 >= ipnr2[1]) and
     ((i2 >= ipnr2[2])or over = true) and ((i3 > ipnr2[3]) or over = true) then
  begin
    Me_Output.Lines.Add('Scanning finish!');
    Bt_Start.Enabled := true;
    Bt_Stop.Enabled := false;
  end
  else
  begin
  // Progress
  inc(z);
  perc_real := 100 / scanips;
  progr_real := z * perc_real;
  Str(progr_real:3:0,strtemp1);
  Val(strtemp1,progr_int,error);
  gauge1.Position := progr_int;
  // Build IP
  Str(Ipnr1[0],strtemp1);
  iptemp := strtemp1 + '.';
  Str(i1,strtemp1);
  iptemp := iptemp + strtemp1 + '.';
  Str(i2,strtemp1);
  iptemp := iptemp + strtemp1 + '.';
  Str(i3,strtemp1);
  iptemp := iptemp + strtemp1;
  ClientSocket.Host := iptemp;

  inc(i3);    // Inc IP
  if i3 > 255 then begin i3 := 0; inc(i2); over := true end;
  if i2 > 255 then begin i2 := 0; inc(i1); over2 := true end;
  if i1 > 255 then begin i1 := 0; end;

  ClientSocket.Open;
  end; // End Scan

end;



procedure TForm1.ClientSocketError(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
ErrorCode := 0;
Scan(ClientSocket, Me_Output, Bt_Start, Bt_Stop, Gauge1); // Call Procedure Scan
end;

procedure TForm1.ClientSocketConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  Me_Output.Lines.Add('Port open: ' + ClientSocket.Host);
  ClientSocket.Close;
  Scan(ClientSocket, Me_Output, Bt_Start, Bt_Stop, Gauge1); // Call Procedure Scan
end;

procedure TForm1.Bt_StartClick(Sender: TObject);

var iptemp,ipnrtemp,strtemp1:String;
var i,ipnrint,error,inttemp1:Integer;
var realerror:Boolean;
begin
  SetLength(Ipnr1, 4);
  SetLength(Ipnr2, 4);
  z := 0;
  over := false;
  over2 := false;
  Gauge1.Position := 0;
  realerror := false;
  Me_Output.Clear;
  Bt_Start.Enabled := false;
  Bt_Stop.Enabled := true;
  {Begin Check IP}


   iptemp := Ed_Ip1.Text;
   for i := 0 to 3 do
   begin
     If i <> 3 then ipnrtemp := Copy(iptemp,1,Pos('.',iptemp)-1)
     else ipnrtemp := iptemp;
     val(ipnrtemp,ipnrint,error);
     If error = 0 then
     begin
       IPnr1[i] := ipnrint;
       Delete(iptemp,1,Pos('.',iptemp));
     end // End If
     else realerror := true;
   end; // End For


   iptemp := Ed_Ip2.Text;
   for i := 0 to 3 do
   begin
     If i <> 3 then ipnrtemp := Copy(iptemp,1,Pos('.',iptemp)-1)
     else ipnrtemp := iptemp;
     val(ipnrtemp,ipnrint,error);
     If error = 0 then
     begin
       IPnr2[i] := ipnrint;
       Delete(iptemp,1,Pos('.',iptemp));
     end // End If
     else realerror := true;
   end; // End For

   If (Ipnr1[0] > 255)or(Ipnr1[1] > 255)or(Ipnr1[2] > 255)or(Ipnr1[3] > 255)or
      (Ipnr2[0] > 255)or(Ipnr2[1] > 255)or(Ipnr2[2] > 255)or(Ipnr2[3] > 255)or
      (IPnr1[1] > Ipnr2[1])or(IPnr1[2] > Ipnr2[2])or(IPnr1[3] > Ipnr2[3])
   then realerror := true;

   If realerror = true then Me_Output.Lines.Add('Start or End IP is wrong!')
   else
   begin
   {Begin Ip right / Start Scan}
     If Ipnr1[0] < Ipnr2[0] then Me_Output.Lines.Add('Start Ip must be smaller then End IP!') else
     begin
       If Ipnr1[0] <> Ipnr2[0] then Me_Output.Lines.Add('The differnt between Start and End Ip is to big!') else
       begin

       scanips := Ipnr2[3] - Ipnr1[3] + 1;
       scanips := scanips + ((Ipnr2[2] - Ipnr1[2]) * 256);
       scanips := scanips + ((Ipnr2[1] - Ipnr1[1]) * 256 * 256);
       // Count the to scanning IPs
       Str(scanips,strtemp1);
       Me_Output.Lines.Add('Scanning: ' + strtemp1 + ' IPs');
       VAL(Ed_Port.Text,inttemp1,error);
       If error = 0 then
       begin
         ClientSocket.Port := inttemp1;

         i1 := Ipnr1[1];
         i2 := Ipnr1[2];
         i3 := Ipnr1[3];

         Scan(ClientSocket, Me_Output, Bt_Start, Bt_Stop, Gauge1); // Call Procedure Scan

       end {End CheckPort}
       else Me_Output.Lines.Add('Port Error');
       end; {End Ip1 <> Ip2}
     end; {End Ip1 < Ip2}
   {End Ip right / Start Scan}
   end; {End no error!}
  {End Check IP}

end;

procedure TForm1.Bt_StopClick(Sender: TObject);
begin
  Bt_Start.Enabled := true;
  Bt_Stop.Enabled := false;
  i1 := Ipnr2[1];
  i2 := Ipnr2[2];
  i3 := Ipnr2[3];
  Me_Output.Lines.Add('Stop!');
end;

end.
Angehängte Dateien
Dateityp: rar portscanner_122.rar (10,1 KB, 26x aufgerufen)
  Mit Zitat antworten Zitat