line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::DHCPparse; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
643
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
7
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
908
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
10
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
11
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
12
|
|
|
|
|
|
|
@EXPORT = qw(leaseparse leaseparsenc); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '0.10'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub leaseparse { |
17
|
0
|
|
|
0
|
0
|
|
my $logfile = shift; |
18
|
0
|
|
|
|
|
|
my ( %list, $ip ); |
19
|
0
|
0
|
|
|
|
|
open FILE, $logfile or die; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
while () { |
22
|
0
|
0
|
|
|
|
|
next if /^#|^$/; |
23
|
0
|
0
|
|
|
|
|
if (/^lease (\d+\.\d+\.\d+\.\d+)/) { |
24
|
0
|
|
|
|
|
|
$ip = $1; |
25
|
0
|
|
|
|
|
|
$list{$ip} = sprintf("%-17s", $ip); |
26
|
|
|
|
|
|
|
} |
27
|
0
|
0
|
|
|
|
|
/^\s*hardware ethernet (.*);/ && ($list{$ip} .= sprintf("%-19s", $1)); |
28
|
0
|
0
|
|
|
|
|
/^\s*starts \d (.*);/ && ($list{$ip} .= sprintf("%-21s", $1)); |
29
|
0
|
0
|
|
|
|
|
/^\s*(abandoned).*/ && ($list{$ip} .= sprintf("%-19s", $1)); |
30
|
0
|
0
|
|
|
|
|
/^\s*client-hostname "(.*)";/ && ($list{$ip} .= sprintf("%-17s", $1)); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
close FILE; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# make all entries 74 characters long to format properly |
36
|
0
|
|
|
|
|
|
foreach (keys %list) { |
37
|
|
|
|
|
|
|
#$list{$_} = sprintf("%-74s", $list{$_}) if (length$list{$_} < 76); |
38
|
0
|
|
|
|
|
|
$list{$_} = sprintf("%-74.74s", $list{$_}); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
return \%list; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub leaseparsenc { |
45
|
|
|
|
|
|
|
# Same as leaseparse, but no colons in MAC and field is 5 characters shorter |
46
|
0
|
|
|
0
|
0
|
|
my $logfile = shift; |
47
|
0
|
|
|
|
|
|
my ( %list, $ip ); |
48
|
0
|
0
|
|
|
|
|
open FILE, $logfile or die; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
while () { |
51
|
0
|
0
|
|
|
|
|
next if /^#|^$/; |
52
|
0
|
0
|
|
|
|
|
if (/^lease (\d+\.\d+\.\d+\.\d+)/) { |
53
|
0
|
|
|
|
|
|
$ip = $1; |
54
|
0
|
|
|
|
|
|
$list{$ip} = sprintf("%-17s", $ip); |
55
|
|
|
|
|
|
|
} |
56
|
0
|
0
|
|
|
|
|
if ( /^\s*hardware ethernet (.*);/) { |
57
|
0
|
|
|
|
|
|
(my $mac = $1) =~ s/://g; |
58
|
0
|
|
|
|
|
|
$list{$ip} .= sprintf("%-14s", $mac); |
59
|
|
|
|
|
|
|
} |
60
|
0
|
0
|
|
|
|
|
/^\s*starts \d (.*);/ && ($list{$ip} .= sprintf("%-21s", $1)); |
61
|
0
|
0
|
|
|
|
|
/^\s*(abandoned).*/ && ($list{$ip} .= sprintf("%-14s", $1)); |
62
|
0
|
0
|
|
|
|
|
/^\s*client-hostname "(.*)";/ && ($list{$ip} .= sprintf("%-17s", $1)); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
close FILE; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# make all entries 69 characters long to format properly |
68
|
0
|
|
|
|
|
|
foreach (keys %list) { |
69
|
|
|
|
|
|
|
#$list{$_} = sprintf("%-69s", $list{$_}) if (length$list{$_} < 76); |
70
|
0
|
|
|
|
|
|
$list{$_} = sprintf("%-69.69s", $list{$_}); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return \%list; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |