-
Notifications
You must be signed in to change notification settings - Fork 2
/
sniffer.pl
executable file
·85 lines (73 loc) · 2.28 KB
/
sniffer.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env perl
#
# Use PoCo::Pcap to analyze DNS Packets for
# potential problems with the DNS infrastructure.
#
# Code by Brad Lhotsky <brad@divisionbyzero.net>
#
use strict;
use warnings;
use FindBin;
# Add local lib path
use lib "$FindBin::Bin/../lib";
# File name processing
use File::Spec;
use File::Basename;
# Config Parsing
use YAML;
use DBIx::Connector;
# POE Environment
sub POE::Kernel::ASSERT_DEFAULT () { 1 }
use EV;
use POE qw(
Loop::EV
Component::Daemon
Component::Logger
Component::dns::monitor::sniffer
);
# Handle interrupts gracefully
$SIG{INT} = sub { exit };
#------------------------------------------------------------------------#
# Locate all the necessary directories
my @BasePath = File::Spec->splitdir( $FindBin::Bin );
pop @BasePath;
my %DIRS = (
'base' => File::Spec->catdir( @BasePath ),
'lib' => File::Spec->catdir( @BasePath, 'lib' ),
'etc' => File::Spec->catdir( @BasePath, 'conf' ),
'cache' => File::Spec->catdir( @BasePath, 'cache' ),
'db' => File::Spec->catdir( @BasePath, 'cache', 'db' ),
'rrd' => File::Spec->catdir( @BasePath, 'cache', 'rrd' ),
);
#------------------------------------------------------------------------#
# Load Configuration
my $configFile = File::Spec->catfile( $DIRS{base}, 'dns_monitor.yml' );
my $CFG = YAML::LoadFile( $configFile ) or die "unable to load $configFile: $!\n";
# Connect to the Database:
my $dbConn = DBIx::Connector->new( $CFG->{db}{dsn}, $CFG->{db}{user}, $CFG->{db}{pass},
{ RaiseError => 0 } );
#------------------------------------------------------------------------#
# POE Environment Setup
#------------------------------------------------------------------------#
#POE::Component::Daemon->spawn( detach => 1, babysit => 600, max_children => 5 );
#
# Setup the Logger
POE::Component::Logger->spawn(
Alias => 'log',
ConfigFile => $CFG->{log_cfg},
);
#
# Start Packet Capturing
POE::Component::dns::monitor::sniffer->spawn(
Config => $configFile,
DBH => $dbConn,
Plugins => $CFG->{plugins},
PcapOpts => $CFG->{pcap},
RRDOpts => $CFG->{rrd},
);
#------------------------------------------------------------------------#
# Run the POE Sessions
#------------------------------------------------------------------------#
POE::Kernel->run;
#------------------------------------------------------------------------#
exit 0;