📄 u_sniffer.pas
字号:
(*
* One Way Network Sniffer (OWNS)
* Copyright (C) 2001-2002 OWNS
*
* http://owns.sourceforge.net/
* http://www.owns.st
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)
(* $Id: u_Sniffer.pas,v 1.5 2002/11/23 21:39:18 owns Exp $
* TWinpCapSniffer, TSehSniffer and TObserverSniffer inherits from this abstract class
* Sample code to use a Sniffer :
*
* if TLibpCapSniffer.isAvailable then
* begin
* FLibpCapSniffer := TLibpCapSniffer.create;
* FLibpCapSniffer.getAdapters(errStr); // you should handle errors here
* FLibpCapSniffer.OnPacket := OnPacket;
* FLibpcap.Activate(errStr);
* end;
* // When you have finished :
* FLibpcap.Deactivate(errStr);
* FLibpCapSniffer.free;
*
*
* procedure TCapture.OnPacket(p_packet : Pointer; p_RecvBytes: Word; p_Tick : Cardinal);
* begin
* // handle the captured packet here
* end;
*
*)
unit u_Sniffer;
interface
uses classes,sysutils;
type
TPacketEvent = procedure(p_packet : Pointer; p_RecvBytes: Word; p_Tick : Cardinal) of object;
TEndSniffingEvent = procedure of object;
// some sniffers read packets from dump files or capture them from an adapter
TModeCapture = (live,offline);
TSniffer = class(TObject)
protected
FSnoopStarted : Boolean;
FNbPacketsReceived : LongInt;
FBytesReceived : Int64;
FPacketEvent : TPacketEvent;
FEndSniffing : TEndSniffingEvent;
FFilePath : String;
FAdapters : TStrings;
FadapterIndex : Integer;
FMode : TModeCapture;
public
constructor create; virtual;
destructor Destroy; override;
function getAdapters(var ErrStr : String) : boolean; virtual; abstract;
function Activate(var ErrStr: string) : Boolean; virtual; abstract;
function Deactivate(var ErrStr: string): boolean; virtual; abstract;
procedure SetAdapterIndex(const Value: integer); virtual;
class function isAvailable : boolean; virtual;
property Snooping : boolean read FSnoopStarted;
property NbPacketsReceived : LongInt read FNbPacketsReceived;
property bytesReceived : Int64 read FBytesReceived;
property OnPacket: TPacketEvent read FPacketEvent write FPacketEvent;
property OnEndSniffing : TEndSniffingEvent read FEndSniffing write FEndSniffing;
// the list of adapters from which we can capture (not supported by observer "sniffer")
property Adapters : Tstrings read Fadapters;
// the file from which we get the packets (not supported by some sniffers)
property FilePath : String read FFilePath write FFilePath;
property AdapterIndex:integer read FadapterIndex write SetAdapterIndex;
// tells if we use a dump file or an adapter network card
property mode : TModeCapture read FMode write FMode;
end;
implementation
constructor TSniffer.create;
begin
inherited Create;
FNbPacketsReceived := 0;
FBytesReceived := 0;
FSnoopStarted := false;
FPacketEvent := nil;
FEndSniffing := nil;
FFilePath := '';
FAdapters := nil;
FadapterIndex := 0;
FMode := live;
FAdapters := TStringList.Create;
end;
destructor TSniffer.Destroy;
begin
FAdapters.Free;
FAdapters := nil;
inherited Destroy;
end;
// select an adapter
procedure TSniffer.SetAdapterIndex(const Value: integer);
begin
if (Adapters = nil) then
exit; // cannot select an adapter : probably observer "sniffer"
if (value>-1) and (value<Adapters.count) then
FadapterIndex := Value;
end;
// is the sniffer available (dll present etc ...)
// Note that this not means that the sniffer can be used (because of security rights
// for example)
class function TSniffer.isAvailable : boolean;
begin
result := true;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -