unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  TFlatButtonUnit, ExtCtrls, TFlatPanelUnit, StdCtrls, TFlatHintUnit,
  ScktComp, TFlatMemoUnit, TFlatRadioButtonUnit, TFlatEditUnit,
  TFlatSpinEditUnit, BUFormAnimation;

type
  TForm2 = class(TForm)
    FlatPanel1: TFlatPanel;
    FlatButton1: TFlatButton;
    FlatButton2: TFlatButton;
    FlatPanel2: TFlatPanel;
    IP1: TFlatSpinEditInteger;
    IP2: TFlatSpinEditInteger;
    IP3: TFlatSpinEditInteger;
    IP4: TFlatSpinEditInteger;
    Radioip2: TFlatRadioButton;
    Radioip3: TFlatRadioButton;
    Radioip4: TFlatRadioButton;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    IPbegin: TFlatSpinEditInteger;
    IPend: TFlatSpinEditInteger;
    port1: TFlatSpinEditInteger;
    Memo1: TFlatMemo;
    Label4: TLabel;
    Button2: TFlatButton;
    Button1: TFlatButton;
    ClientSocket1: TClientSocket;
    FlatHint1: TFlatHint;
    ipcountend: TEdit;
    Radioip1: TRadioButton;
    ListBox1: TListBox;
    scanagain: TCheckBox;
    ip: TLabel;
    BUFormAnimation2: TBUFormAnimation;
    procedure FlatButton1Click(Sender: TObject);
    procedure FlatButton2Click(Sender: TObject);
    procedure ClientSocket1Connect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ClientSocket1Connecting(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure scanagainClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Radioip4Click(Sender: TObject);
    procedure Radioip3Click(Sender: TObject);
    procedure Radioip2Click(Sender: TObject);
    procedure Radioip1Click(Sender: TObject);
    procedure ipcountendChange(Sender: TObject);
    procedure FlatPanel1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  type iptype = record
                ipcount, pcount:integer;
                ip:array[0..99] of string[25];
                port:array [0..99] of integer;

   end;

var
  Form2: TForm2;
  IP_base, IP_count, CurrPort : integer;
  CurrIP  : string;
  Connection, ServerAnswer,scanning : boolean;
  
implementation

{$R *.DFM}

procedure TForm2.FlatButton1Click(Sender: TObject);
begin
Form2.close;
end;

procedure TForm2.FlatButton2Click(Sender: TObject);
begin
Form2.WindowState:=wsMinimized;
end;

procedure TForm2.ClientSocket1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
clientsocket1.address := IP.caption;
  ServerAnswer:=true;
  Connection:=false;
  Memo1.Lines.Add ( 'Found Victim : ' + Socket.RemoteAddress);
  sleep(100);
  IP4.enabled:=false;
  IP3.enabled:=true;
  IP2.enabled:=true;
  IP1.enabled:=true;
  Radioip4.checked:=true;
  clientsocket1.close;
end;

procedure TForm2.ClientSocket1Connecting(Sender: TObject;
  Socket: TCustomWinSocket);
begin
Label4.Caption:= ( 'Scanning : '+IP.caption);
end;

procedure TForm2.ClientSocket1Error(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
  ServerAnswer:=true;
  Connection:=false;
  ErrorCode := 0;
  sleep(500);
  scanagain.checked:=true;
end;

procedure TForm2.Button2Click(Sender: TObject);
var
  Index: Integer;
begin
  clientsocket1.close;
  clientsocket1.active :=false;

  ipcountend.text :=inttostr(ipbegin.value);
  ListBox1.clear;

  for Index := IPbegin.value to IPend.value do
  ListBox1.Items.add (inttostr(index));

  listbox1.items.add('*#*#*#*');

  if Radioip4.checked = true then begin
  ip.caption := inttostr(IP1.value)+'.'+inttostr(IP2.value)+'.'+inttostr(IP3.value)+'.'+ipcountend.text;
  end;
  if Radioip3.checked = true then begin
  ip.caption := inttostr(IP1.value)+'.'+inttostr(IP2.value)+'.'+ipcountend.text+'.'+inttostr(IP4.value);
  end;
  if Radioip2.checked = true then begin
  ip.caption := inttostr(IP1.value)+'.'+ipcountend.text+'.'+inttostr(IP3.value)+'.'+inttostr(IP4.value);
  end;
  if Radioip1.checked = true then begin
  ip.caption := ipcountend.text+'.'+inttostr(IP2.value)+'.'+inttostr(IP3.value)+inttostr(IP4.value);
  end;

  ClientSocket1.Port:=port1.value;
  ClientSocket1.Address:= IP.caption;

  if (Length(ip.caption)>0) then
   begin
   clientsocket1.close;
   ClientSocket1.Port:= port1.value;
   end;
   CurrPort:=ClientSocket1.Port;
   if Pos('+', IP.caption)=0 then
   begin
   scanning:=false;
   CurrIP:=IP.caption;
   with ClientSocket1 do
   begin
   Address := IP.caption;
   Open;
   end;
   end;
   end;

procedure TForm2.Button1Click(Sender: TObject);
begin
ipcountend.text:='*#*#*#*';
scanning:=false;
Connection:=false;
clientsocket1.active :=false;
clientsocket1.close;
IP4.enabled:=false;
IP3.enabled:=true;
IP2.enabled:=true;
IP1.enabled:=true;
Radioip4.checked:=true;
end;

procedure TForm2.scanagainClick(Sender: TObject);
begin
if scanagain.checked=true then begin
  scanagain.checked:=false;
  
  if ipcountend.text = '*#*#*#*' then begin
  scanning:=false;
  Connection:=false;
  clientsocket1.active :=false;
  clientsocket1.close;
  exit;
  halt;
  end;

  with ListBox1.Items do
  begin
  Delete(IndexOf(ipcountend.text));
  ipcountend.text := ListBox1.Items[0];
  end;

   if (Length(ip.caption)>0) then
   begin
   clientsocket1.close;
   ClientSocket1.Port:= port1.value;
   end;
   CurrPort:=ClientSocket1.Port;
   if Pos('+', IP.caption)=0 then
   begin
   scanning:=false;
   CurrIP:=IP.caption;
   with ClientSocket1 do
   begin
   Address := IP.caption;
   Open;
   end;
   end;
   end;
end;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
clientsocket1.close;
end;

procedure TForm2.Radioip4Click(Sender: TObject);
begin
IP4.enabled:=false;
IP3.enabled:=true;
IP2.enabled:=true;
IP1.enabled:=true;
end;

procedure TForm2.Radioip3Click(Sender: TObject);
begin
IP3.enabled:=false;
IP4.enabled:=true;
IP2.enabled:=true;
IP1.enabled:=true;
end;

procedure TForm2.Radioip2Click(Sender: TObject);
begin
IP2.enabled:=false;
IP3.enabled:=true;
IP4.enabled:=true;
IP1.enabled:=true;
end;

procedure TForm2.Radioip1Click(Sender: TObject);
begin
IP1.enabled:=false;
IP3.enabled:=true;
IP2.enabled:=true;
IP4.enabled:=true;
end;

procedure TForm2.ipcountendChange(Sender: TObject);
begin
if ipcountend.text='*#*#*#*' then begin exit
  end else
  
  if Radioip4.checked = true then begin
  ip.caption := inttostr(IP1.value)+'.'+inttostr(IP2.value)+'.'+inttostr(IP3.value)+'.'+ipcountend.text;
  end;
  if not pos('*#*#*#*',ipcountend.text) < 1 then begin
  if Radioip4.checked = true then begin
  ip.caption := inttostr(IP1.value)+'.'+inttostr(IP2.value)+'.'+inttostr(IP3.value)+'.'+ipcountend.text;
  end;
  if Radioip3.checked = true then begin
  ip.caption := inttostr(IP1.value)+'.'+inttostr(IP2.value)+'.'+ipcountend.text+'.'+inttostr(IP4.value);
  end;
  if Radioip2.checked = true then begin
  ip.caption := inttostr(IP1.value)+'.'+ipcountend.text+'.'+inttostr(IP3.value)+'.'+inttostr(IP4.value);
  end;
  if Radioip1.checked = true then begin
  ip.caption := ipcountend.text+'.'+inttostr(IP2.value)+'.'+inttostr(IP3.value)+inttostr(IP4.value);
  end;
  end;
  end;


procedure TForm2.FlatPanel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 ReleaseCapture;
 Perform(WM_NCLBUTTONDOWN,HTCAPTION,0);

end;

procedure TForm2.FormActivate(Sender: TObject);
begin
BUFormAnimation2.AppearRectangle;
end;

end.
