Skip to content

Commit

Permalink
feat: Creates scan list
Browse files Browse the repository at this point in the history
It also displays an exit message stating one should wait until memory is freed from the scan list
  • Loading branch information
gcarreno committed Dec 21, 2023
1 parent cb76d61 commit 8bfab2f
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/TestIPScanner.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
<Icon Value="0"/>
</General>
<BuildModes Count="3">
<Item1 Name="Default" Default="True"/>
Expand Down
55 changes: 50 additions & 5 deletions src/forms/forms.main.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,29 @@ object frmMain: TfrmMain
Menu = mmMain
Position = poDefault
SessionProperties = 'edtPingHost.Text;edtTraceHost.Text;Height;Left;pcMain.ActivePage;Top;Width;WindowState;edtScanStartIP.Text;edtScanEndIP.Text'
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnDestroy = FormDestroy
OnShow = FormShow
object panExitWarning: TPanel
Left = 20
Height = 50
Top = 40
Width = 170
Caption = 'Please wait until memory is freed from the Scan list'
Font.Height = -40
Font.Style = [fsBold]
ParentFont = False
TabOrder = 1
end
object pcMain: TPageControl
Left = 0
Height = 500
Top = 0
Width = 800
ActivePage = tsPing
ActivePage = tsScan
Align = alClient
TabIndex = 2
TabIndex = 1
TabOrder = 0
object tsMyIP: TTabSheet
Caption = '&My IP'
Expand Down Expand Up @@ -148,19 +160,47 @@ object frmMain: TfrmMain
Enabled = False
TabOrder = 1
end
object btnScanClear: TButton
Left = 215
Height = 33
Top = 4
Width = 100
Action = actScanClear
Align = alLeft
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 4
Constraints.MinWidth = 100
TabOrder = 2
end
end
object vstScan: TLazVirtualStringTree
Cursor = 63
Left = 4
Height = 306
Top = 159
Width = 782
Align = alClient
BorderSpacing.Around = 4
DefaultText = 'Node'
Header.AutoSizeIndex = 0
Header.Columns = <>
Header.MainColumn = -1
DragOperations = []
Header.AutoSizeIndex = -1
Header.Columns = <
item
Position = 0
Text = 'IP'
Width = 150
end
item
Position = 1
Text = 'Status'
Width = 630
end>
Header.Options = [hoAutoResize, hoColumnResize, hoDblClickResize, hoDrag, hoShowSortGlyphs, hoVisible, hoAutoSpring]
TabOrder = 3
TreeOptions.MiscOptions = [toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning, toReadOnly, toEditOnClick]
OnGetText = vstScanGetText
OnGetNodeDataSize = vstScanGetNodeDataSize
end
end
object tsPing: TTabSheet
Expand Down Expand Up @@ -314,6 +354,11 @@ object frmMain: TfrmMain
Caption = 'St&op Scan'
OnExecute = actScanStopExecute
end
object actScanClear: TAction
Category = 'Scan'
Caption = 'Clear'
OnExecute = actScanClearExecute
end
object actPingStart: TAction
Category = 'Ping'
Caption = 'Start Ping'
Expand Down
173 changes: 161 additions & 12 deletions src/forms/forms.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ interface
, ComCtrls
, ActnList
, Menus
, StdActns, StdCtrls, ExtCtrls, IniPropStorage, IPEdit, laz.VirtualTrees
, StdActns
, StdCtrls
, ExtCtrls
, IniPropStorage
, IPEdit
, laz.VirtualTrees
;

type

{ TfrmMain }

TfrmMain = class(TForm)
actScanClear: TAction;
actTraceStart: TAction;
actPingStart: TAction;
actScanStop: TAction;
Expand All @@ -34,6 +40,7 @@ TfrmMain = class(TForm)
btnMyIpFetch: TButton;
btnScanStop: TButton;
btnPingStart: TButton;
btnScanClear: TButton;
edtPingHost: TEdit;
edtTraceHost: TEdit;
edtScanStartIP: TIPEdit;
Expand All @@ -44,6 +51,7 @@ TfrmMain = class(TForm)
memMyIPLog: TMemo;
memPingLog: TMemo;
memTraceLog: TMemo;
panExitWarning: TPanel;
panPingButtons: TPanel;
panMyIPButtons: TPanel;
panTraceButtons: TPanel;
Expand All @@ -62,19 +70,24 @@ TfrmMain = class(TForm)
procedure actMyIPFetchExecute(Sender: TObject);
procedure actScanStartExecute(Sender: TObject);
procedure actScanStopExecute(Sender: TObject);
procedure actScanClearExecute(Sender: TObject);
procedure actPingStartExecute(Sender: TObject);
procedure actTraceStartExecute(Sender: TObject);
procedure alMainUpdate(AAction: TBasicAction; var Handled: Boolean);
procedure vstScanGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
procedure vstScanGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormDestroy(Sender: TObject);

procedure EnablePropertyStorage;
procedure DisablePropertyStorage;
procedure InitShortcuts;
procedure EnableControls;
procedure DisableControls;
procedure pcMainChange(Sender: TObject);
private

public
Expand Down Expand Up @@ -102,6 +115,16 @@ implementation
'ipecho.net/plain'
);

type
PScanEntry = ^TScanEntry;
TScanEntry = record
IP: String;
Status: String;
end;

var
DisplayExitMessage: Boolean = False;

{$R *.lfm}

{ TfrmMain }
Expand All @@ -127,11 +150,22 @@ procedure TfrmMain.FormShow(Sender: TObject);
// Do nothing
end;
3:begin // Trate Route
edtTraceHost.SetFocus;
// Do Nothing
end;
end;
end;

procedure TfrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if DisplayExitMessage then
begin
pcMain.Visible:= False;
panExitWarning.Align:= alClient;
Application.ProcessMessages;
end;
CanClose:= True;
end;

procedure TfrmMain.FormDestroy(Sender: TObject);
begin
DisablePropertyStorage;
Expand Down Expand Up @@ -176,18 +210,46 @@ procedure TfrmMain.DisableControls;
pcMain.Enabled:= False;
end;

procedure TfrmMain.pcMainChange(Sender: TObject);
begin

end;

procedure TfrmMain.alMainUpdate(AAction: TBasicAction; var Handled: Boolean);
begin
if AAction = actScanStop then
begin
actScanStop.Enabled:= not actScanStart.Enabled;
Handled:= True;
end;
if AAction = actScanClear then
begin
actScanClear.Enabled:= (vstScan.RootNodeCount > 0) and (actScanStart.Enabled);
Handled:= True;
end;
end;

procedure TfrmMain.vstScanGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
begin
NodeDataSize:= SizeOf(TScanEntry);
end;

procedure TfrmMain.vstScanGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
var
entry: PScanEntry;
begin
if Assigned(Node) then
begin
entry:= Sender.GetNodeData(Node);
if Assigned(entry) then
begin
case Column of
0:begin
CellText:= entry^.IP;
end;
1:begin
CellText:= entry^.Status;
end;
end;
end;
end;
end;

procedure TfrmMain.actMyIPFetchExecute(Sender: TObject);
Expand Down Expand Up @@ -238,19 +300,106 @@ procedure TfrmMain.actMyIPFetchExecute(Sender: TObject);
end;

procedure TfrmMain.actScanStartExecute(Sender: TObject);
var
node: PVirtualNode = nil;
entry: PScanEntry = nil;
index0,
index1,
index2,
index3: Integer;
quadStart,
quadEnd: TStringArray;
begin
DisplayExitMessage:= True;

actScanStart.Enabled:= False;
Application.ProcessMessages;
try

ShowMessage('Not Implemented yet.');
quadStart:= edtScanStartIP.TextTrimmed.Split(['.']);
quadEnd:= edtScanEndIP.TextTrimmed.Split(['.']);

Application.ProcessMessages;
actScanStart.Enabled:= True;
if (StrToInt(quadStart[0]) > StrToInt(quadEnd[0])) or
(StrToInt(quadStart[1]) > StrToInt(quadEnd[1])) or
(StrToInt(quadStart[2]) > StrToInt(quadEnd[2])) or
(StrToInt(quadStart[3]) > StrToInt(quadEnd[3])) then
begin
ShowMessage('Start IP should be numerically before End IP');
exit;
end;
vstScan.BeginUpdate;
vstScan.TreeOptions.MiscOptions:= vstScan.TreeOptions.MiscOptions - [toReadOnly];

if vstScan.RootNodeCount > 0 then
begin
vstScan.Clear;
end;

for index0:= StrToInt(quadStart[0]) to StrToInt(quadEnd[0]) do
begin
for index1:= StrToInt(quadStart[1]) to StrToInt(quadEnd[1]) do
begin
for index2:= StrToInt(quadStart[2]) to StrToInt(quadEnd[2]) do
begin
for index3:= StrToInt(quadStart[3]) to StrToInt(quadEnd[3]) do
begin
node:= vstScan.AddChild(vstScan.RootNode);
if Assigned(node) then
begin
entry:= vstScan.GetNodeData(node);
if Assigned(entry) then
begin
entry^.IP:= Format('%d.%d.%d.%d', [
index0,
index1,
index2,
index3
]);
entry^.Status:= 'Waiting';
end;
end;
end;
end;
end;
end;

vstScan.TreeOptions.MiscOptions:= vstScan.TreeOptions.MiscOptions + [toReadOnly];
vstScan.EndUpdate;

finally
Application.ProcessMessages;
//actScanStart.Enabled:= True;
end;
end;

procedure TfrmMain.actScanStopExecute(Sender: TObject);
begin
//
btnScanStop.Enabled:= False;
Application.ProcessMessages;
try

vstScan.BeginUpdate;
vstScan.TreeOptions.MiscOptions:= vstScan.TreeOptions.MiscOptions - [toReadOnly];

vstScan.TreeOptions.MiscOptions:= vstScan.TreeOptions.MiscOptions + [toReadOnly];
vstScan.EndUpdate;

finally
Application.ProcessMessages;
actScanStart.Enabled:= True;
end;
end;

procedure TfrmMain.actScanClearExecute(Sender: TObject);
begin
if vstScan.RootNodeCount > 0 then
begin
vstScan.BeginUpdate;
vstScan.TreeOptions.MiscOptions:= vstScan.TreeOptions.MiscOptions - [toReadOnly];
vstScan.Clear;
vstScan.TreeOptions.MiscOptions:= vstScan.TreeOptions.MiscOptions + [toReadOnly];
vstScan.EndUpdate;
end;
end;

procedure TfrmMain.actPingStartExecute(Sender: TObject);
Expand Down
2 changes: 1 addition & 1 deletion src/version.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'0.3.1'
'0.3.2'

0 comments on commit 8bfab2f

Please sign in to comment.