• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Small program to read log text file

Well in Delphi.  Somebody can make me a small program?

I'm fed up reading and analysing log files.  ftp://ftp.exceltheque.com/  Look the example of log file.  I would like to have a program that would add each identical ip address in order to see who is attempting to access my network.  

For example, i see 24.200.1.35 often.  The program could give me the amount of attempts to connect one shot without me to count them.  

I have an old delphi 1 licence to compile otherwise, could you send me an executable?  
merlin740500@hotmail.com

Do not forget to write something here too to have points.  

Thank you,

M.
0
Merlin740500
Asked:
Merlin740500
  • 2
1 Solution
 
shaneholmesCommented:
I have sent you a zipped up executable with source

sholmes

See code below:


unit untMain;

interface

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

type
  TfrmMain = class(TForm)
    pnlTop: TPanel;
    pnlBottom: TPanel;
    btnLoad: TButton;
    dlgOpen: TOpenDialog;
    lbxItems: TListBox;
    procedure btnLoadClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

{$R *.dfm}

procedure TfrmMain.btnLoadClick(Sender: TObject);
var
 AList: TStringList;
 I: Integer;
begin
 if dlgOpen.Execute then
 begin
  AList:= TSTringList.Create;
  AList.LoadFromFile(dlgOpen.FileName);
  for I:= 1 to AList.Count - 1 do
  begin
   if Pos('Blocked access attempt from',AList[I]) > 0 then
    lbxItems.Items.Add(Copy(AList[I],50, Length(AList[I])) + ' - ' + 'Blocked access' + ' - ' +
                       Copy(Alist[I],1,18))
   else
   if Pos('login Successful', Alist[I]) > 0 then
    lbxItems.Items.Add(Copy(AList[I],22, pos('login Successful',AList[I])- 22) + ' - ' +  'login Successful' + ' - ' +
                       Copy(Alist[I],1,18))
   else
   if Pos('logout', Alist[I]) > 0 then
    lbxItems.Items.Add(Copy(AList[I],22, pos('logout',AList[I])-22) + ' - ' +  'logout' + ' - ' +
                       Copy(Alist[I],1,18));

  end;
  AList.Free;
 end;
end;

end.
0
 
Merlin740500Author Commented:
Your codes impress me, it is efficient!

I've taken a course at the university ten years ago and never practice since.  Just able to follow the program!
0
 
shaneholmesCommented:
Thanx for the points!

I have included comments for you to follow

procedure TfrmMain.btnLoadClick(Sender: TObject);
var
 AList: TStringList;
 I: Integer;
begin

 //execute the open file dialog box
 if dlgOpen.Execute then
 begin
  // create a list to temporarily store entire file
  AList:= TSTringList.Create;

  //load entire file into temp list
  AList.LoadFromFile(dlgOpen.FileName);

 // iterate through each line in file
  for I:= 1 to AList.Count - 1 do
  begin
   
   //test for the position of 'Blocked access attempt from' in the line
   if Pos('Blocked access attempt from',AList[I]) > 0 then
    rearrange each part of the line so that the Ip address goes first
    lbxItems.Items.Add(Copy(AList[I],50, Length(AList[I])) + ' - ' + 'Blocked access' + ' - ' +
                       Copy(Alist[I],1,18))
   else
  // do the same for others down below

   if Pos('login Successful', Alist[I]) > 0 then
    lbxItems.Items.Add(Copy(AList[I],22, pos('login Successful',AList[I])- 22) + ' - ' +  'login Successful' + ' - ' +
                       Copy(Alist[I],1,18))
   else
   if Pos('logout', Alist[I]) > 0 then
    lbxItems.Items.Add(Copy(AList[I],22, pos('logout',AList[I])-22) + ' - ' +  'logout' + ' - ' +
                       Copy(Alist[I],1,18));

  end;
  AList.Free;
 end;
end;



Hope this helps!

Sholmes
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now