http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrpt.pl&feed=atom&action=history
/root/scripts/bwrpt.pl - Revision history
2024-03-29T05:07:41Z
Revision history for this page on the wiki
MediaWiki 1.41.0
http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrpt.pl&diff=446&oldid=prev
Bob at 19:19, 12 August 2015
2015-08-12T19:19:12Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:19, 12 August 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l8">Line 8:</td>
<td colspan="2" class="diff-lineno">Line 8:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>## This should cover any packages required on a standard debian box:</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>## This should cover any packages required on a standard debian box:</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>## apt-get install libfile-tail-perl libtext-trim-perl libdatetime-format-mail-perl libnet-sslglue-perl</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>## apt-get install libfile-tail-perl libtext-trim-perl libdatetime-format-mail-perl libnet-sslglue-perl <ins style="font-weight: bold; text-decoration: none;">nbtscan</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>## This script depends on configuration of the iptaccount module available in xtables-addons</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>## This script depends on configuration of the iptaccount module available in xtables-addons</div></td></tr>
</table>
Bob
http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrpt.pl&diff=412&oldid=prev
Bob at 00:05, 9 July 2014
2014-07-09T00:05:36Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 20:05, 8 July 2014</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l394">Line 394:</td>
<td colspan="2" class="diff-lineno">Line 394:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> print RPT "\n";</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> print RPT "\n";</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> printf (RPT "%-15s%6s%6s%6s%6s%6s%6s%19s%6s\n", "IP ADDR", "DAYDN", "DAYUP", "DAYTL", "MTDDN", "MTDUP", "MTDTL", "Last Seen Host ", "Host #");</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> printf (RPT "%-15s%6s%6s%6s%6s%6s%6s%19s%6s\n", "IP ADDR", "DAYDN", "DAYUP", "DAYTL", "MTDDN", "MTDUP", "MTDTL", "Last Seen Host ", "Host #");</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"># if ( keys %{$daily{$thisday}{$i}} ) {</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> foreach my $ips (sort ( keys %{$daily{$thisday}{$i}} ) ) {</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> foreach my $ips (sort ( keys %{$daily{$thisday}{$i}} ) ) {</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> printf (RPT "%-15s%6s%6s%6s%6s%6s%6s%19s%6s\n", $ips, int($daily{$thisday}{$i}{$ips}{ttlout}/$mb/$mb), int($daily{$thisday}{$i}{$ips}{ttlin}/$mb/$mb), int($daily{$thisday}{$i}{$ips}{ttl}/$mb/$mb), int($daily{$i}{$ips}{mtdttlout}/$mb/$mb), int($daily{$i}{$ips}{mtdttlin}/$mb/$mb), int($daily{$i}{$ips}{mtdttl}/$mb/$mb), $daily{$thisday}{$i}{$ips}{devname}, $daily{$thisday}{$i}{$ips}{devchange});</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> printf (RPT "%-15s%6s%6s%6s%6s%6s%6s%19s%6s\n", $ips, int($daily{$thisday}{$i}{$ips}{ttlout}/$mb/$mb), int($daily{$thisday}{$i}{$ips}{ttlin}/$mb/$mb), int($daily{$thisday}{$i}{$ips}{ttl}/$mb/$mb), int($daily{$i}{$ips}{mtdttlout}/$mb/$mb), int($daily{$i}{$ips}{mtdttlin}/$mb/$mb), int($daily{$i}{$ips}{mtdttl}/$mb/$mb), $daily{$thisday}{$i}{$ips}{devname}, $daily{$thisday}{$i}{$ips}{devchange});</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> }</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> }</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"># }</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> }</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> }</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> close (RPT);</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> close (RPT);</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l407">Line 407:</td>
<td colspan="2" class="diff-lineno">Line 405:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> my $smtp = Net::SMTP->new( "$smtpserver", SSL => 1, Hello => "$mailhello", SSL_ca_path => '/etc/ssl/certs', SSL_verify_mode => 0) or die "Failed to open SMTP connection: $!";;</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> my $smtp = Net::SMTP->new( "$smtpserver", SSL => 1, Hello => "$mailhello", SSL_ca_path => '/etc/ssl/certs', SSL_verify_mode => 0) or die "Failed to open SMTP connection: $!";;</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"># $smtp->starttls(SSL_ca_path => '/etc/ssl/certs', SSL_verify_mode => 0);</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> $smtp->auth ("$smtpauthname","$smtpauthpass");</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> $smtp->auth ("$smtpauthname","$smtpauthpass");</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> $smtp->mail ("$mailfrom");</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> $smtp->mail ("$mailfrom");</div></td></tr>
</table>
Bob
http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrpt.pl&diff=411&oldid=prev
Bob at 00:04, 9 July 2014
2014-07-09T00:04:33Z
<p></p>
<a href="http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrpt.pl&diff=411&oldid=405">Show changes</a>
Bob
http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrpt.pl&diff=405&oldid=prev
Bob at 03:27, 15 May 2014
2014-05-15T03:27:25Z
<p></p>
<a href="http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrpt.pl&diff=405&oldid=395">Show changes</a>
Bob
http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrpt.pl&diff=395&oldid=prev
Bob at 19:38, 27 April 2014
2014-04-27T19:38:11Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:38, 27 April 2014</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><h5>New Script - Please read the notes at the top as things have changed since [[/root/scripts/<del style="font-weight: bold; text-decoration: none;">bwmon</del>.sh]]</h5></div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><h5>New Script - Please read the notes at the top as things have changed since [[/root/scripts/<ins style="font-weight: bold; text-decoration: none;">bwrprt</ins>.sh]]</h5></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td></tr>
</table>
Bob
http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrpt.pl&diff=394&oldid=prev
Bob at 19:37, 27 April 2014
2014-04-27T19:37:52Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:37, 27 April 2014</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><h5>New Script - Please read the notes at the top as things have changed since [[bwmon.sh]]</h5></div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><h5>New Script - Please read the notes at the top as things have changed since [[<ins style="font-weight: bold; text-decoration: none;">/root/scripts/</ins>bwmon.sh]]</h5></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td></tr>
</table>
Bob
http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrpt.pl&diff=393&oldid=prev
Bob at 19:37, 27 April 2014
2014-04-27T19:37:37Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:37, 27 April 2014</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><h5>New Script - Please read the notes at the top as things have changed since [[bwmon.sh]]</h5></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>#!/usr/bin/perl</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>#!/usr/bin/perl</div></td></tr>
</table>
Bob
http://cocnm.computerisms.ca/index.php?title=/root/scripts/bwrpt.pl&diff=388&oldid=prev
Bob at 03:52, 16 April 2014
2014-04-16T03:52:41Z
<p></p>
<p><b>New page</b></p><div><pre><br />
#!/usr/bin/perl<br />
<br />
# Written by Bob Miller - bob@computerisms.ca<br />
# Converted from Bash Script Feb 2014 and<br />
# modified to account for >4GB/hour internet connections<br />
<br />
## This should cover any packages required on a standard debian box:<br />
## apt-get install libfile-tail-perl libtext-trim-perl<br />
<br />
## This script depends on configuration of the iptaccount module available in xtables-addons<br />
## It assumes each subnet matches one physical interface which matches one iptaccount table name<br />
## Some iptables rules like this should work:<br />
## iptables -t filter -I FORWARD -j ACCOUNT --addr 192.168.25.0/24 --tname lan<br />
## iptables -t mangle -I POSTROUTING -j ACCOUNT --addr 0/0 --tname wan<br />
<br />
## Set cron to run this often enough that the $wrap variable is not exceeded in one run<br />
## For example, on slow connections, this can be run once per hour, on fast connections every<br />
## 10 minutes. It needs to be run offset so that the reporting fires before midnight, something<br />
## Like so will do (note busy systems may need to run 2 minutes before midnight to give the <br />
## script time to run instead of one minute):<br />
## 9-59/10 * * * * PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin; /usr/bin/perl /root/scripts/bwrpt.pl<br />
<br />
#bwrpt.pl<br />
use strict;<br />
use warnings;<br />
use Time::Piece;<br />
use Time::Seconds;<br />
use File::Path qw(make_path);<br />
use File::Tail;<br />
use Text::Trim;<br />
use Net::SMTP;<br />
<br />
####################################################################################<br />
####################################################################################<br />
## ##<br />
## Configuration Options ##<br />
## ##<br />
####################################################################################<br />
####################################################################################<br />
<br />
## Configure WAN ehternet port and matching --tname from iptables<br />
our $wanface = "eth0";<br />
our $wanipt = "wan";<br />
<br />
## From your iptables, list all --tname values here except the wan<br />
our @iptname = ("computerisms", "computerisms-pub", "computerisms2remote");<br />
<br />
## WISHLIST ITEM<br />
## Enable full detail for per-host reporting (set to 0 to disable, set to 1 to enable)<br />
## List each --tname you have in @iptname and enable/disable each one<br />
#our %iptdetail = (<br />
# "computerisms" => 1,<br />
# "computerisms-pub" => 0,<br />
# "computerisms2remote" => 0,<br />
#);<br />
<br />
## Set the base directory to store daily data<br />
our $base = "/root/scripts/bwdata";<br />
<br />
## Set 32-bit system or 64-bit system<br />
our $wrap = 4294967295; ## Uncomment this for 32-bit<br />
#our $wrap = 18446744073709551615; ## Uncomment this for 64-bit<br />
<br />
## Set these values as per the cronjob to the last run of the day to generate and send a report.<br />
our $rpthour = "23";<br />
our $rptmin = "59";<br />
<br />
## Set Mega or Mibi<br />
our $mb = "1000"; ## Uncomment this line for Mega<br />
#our $mb = "1024"; ## Uncomment this line for Mibi<br />
<br />
## Set this to the max bandwidth in GB(GiB) before incurring overage charges<br />
our $maxbw = "90";<br />
<br />
## Configure mail settings<br />
our $smtpserver = "mail.computerisms.com";<br />
our $mailfrom = "firewall\@computerisms.com";<br />
our $mailto = "bob.miller\@computerisms.com";<br />
our $mailhello = "firewall.computerisms.com";<br />
our $smtpauthname = "smtpauth\@computerisms.com";<br />
our $smtpauthpass = "xxxxxxxxx";<br />
<br />
<br />
####################################################################################<br />
####################################################################################<br />
## ##<br />
## You should not need to change anything below here ##<br />
## ##<br />
####################################################################################<br />
####################################################################################<br />
<br />
## Populate time and date variables<br />
<br />
our $date = Time::Piece->new;<br />
our $time = $date->time;<br />
our $hour = $date->hour;<br />
our $min = $date->min;<br />
our $month = $date->strftime('%Y/%m');<br />
our $thisday = $date->strftime('%d');<br />
our $today = $date->ymd("/");<br />
our $yesterday = ($date - ONE_DAY)->ymd("/");<br />
<br />
## Test if Today's directory exists, if not create it<br />
<br />
if (!-d "$base"."/"."$today"."/") {<br />
make_path("$base"."/"."$today");<br />
}<br />
<br />
## Set System Executables<br />
<br />
our $doipt = qx(which iptaccount) or die "cannot find iptaccount program $!";<br />
our $donbt = qx(which nbtscan) or die "cannot find nbtscan program $!";<br />
#our $doarp = qx(which arp) or die "cannot find arp program $!";<br />
chomp ($doipt, $donbt);<br />
<br />
## Now Collect iptaccount data for internal subnets<br />
<br />
for my $curiptname (@iptname) {<br />
if (!-d "$base"."/"."$today"."/"."$curiptname"."/") {<br />
make_path("$base"."/"."$today"."/"."$curiptname");<br />
}<br />
my @ipt = qx($doipt -s -l $curiptname);<br />
my ($lastrun, $hostname);<br />
foreach my $i (@ipt) {<br />
next if $i =~ /^\D/;<br />
chomp $i;<br />
my @ip = split(';', $i);<br />
my $curfile="$base"."/"."$today"."/"."$curiptname"."/"."$ip[0]";<br />
if (!-e $curfile) {<br />
# open IP, ">> $curfile" or die $!;<br />
# print IP "timestamp iptin iptout insince outsince runttlin runttlout runttl wrapin wrapout hostname hostchange\n";<br />
if (-e "$base"."/"."$yesterday"."/"."$curiptname"."/"."$ip[0]") {<br />
my $lastfile = File::Tail->new(name => "$base"."/"."$yesterday"."/"."$curiptname"."/"."$ip[0]", tail => 1);<br />
$lastrun = $lastfile -> read;<br />
my @resetday = split (/ /, $lastrun);<br />
@resetday[5..9,11] = (0) x 6;<br />
$lastrun = "@resetday";<br />
chomp $lastrun;<br />
} else {<br />
$lastrun = "0 0 0 0 0 0 0 0 0 0 undef 0 ";<br />
chomp $lastrun;<br />
}<br />
} else {<br />
my $lastfile = File::Tail->new(name => "$base"."/"."$today"."/"."$curiptname"."/"."$ip[0]", tail => 1) or die $!;<br />
$lastrun = $lastfile -> read;<br />
chomp $lastrun;<br />
}<br />
my @lastrun = split(/ /, $lastrun);<br />
my ($sincelastin, $curttlin, $sincelastout, $curttlout);<br />
if ($lastrun[1] > $ip[2]) {<br />
$lastrun[8]++;<br />
# $sincelastin = $lastrun[8]*$wrap+$ip[2]-$lastrun[5];<br />
$sincelastin = $wrap+$ip[2]-$lastrun[1];<br />
$curttlin = $lastrun[5]+$sincelastin;<br />
} else {<br />
$sincelastin = $ip[2]-$lastrun[1];<br />
$curttlin = $lastrun[5]+$sincelastin;<br />
}<br />
if ($lastrun[2] > $ip[4]) {<br />
$lastrun[9]++;<br />
# $sincelastout = $lastrun[9]*$wrap+$ip[4]-$lastrun[6];<br />
$sincelastout = $wrap+$ip[4]-$lastrun[2];<br />
$curttlout = $lastrun[6]+$sincelastout;<br />
} else {<br />
$sincelastout = $ip[4]-$lastrun[2];<br />
$curttlout = $lastrun[6]+$sincelastout;<br />
}<br />
my $runttl = $curttlin+$curttlout;<br />
next if ( $sincelastin == 0 && $sincelastout == 0 );<br />
my @hostlook;<br />
my $lookup = qx($donbt -s : $ip[0]);<br />
if ( $lookup ne '' ) {<br />
my @hostlook = split (/:/, $lookup);<br />
$hostname = $hostlook[1];<br />
$hostname = trim($hostname);<br />
chomp $hostname;<br />
} else {<br />
$lookup = qx(grep $ip[0] /proc/net/arp);<br />
if ( $lookup ne '' ) {<br />
@hostlook = split (' ', $lookup);<br />
$hostname = $hostlook[3];<br />
$hostname = trim($hostname);<br />
chomp $hostname;<br />
$hostname=$lastrun[10] if ( $hostname =~ /incomplete/ ); <br />
$hostname=$lastrun[10] if ( $hostname =~ /00:00:00:00:00:00/ ); <br />
} else { <br />
$hostname = "NOT DEFINABLE";<br />
chomp $hostname;<br />
}<br />
}<br />
if ( $hostname ne "$lastrun[10]" ) {<br />
$lastrun[11]++;<br />
}<br />
open IP, ">> $curfile" or die $!;<br />
if ( -z $curfile) {<br />
print IP "timestamp iptin iptout insince outsince runttlin runttlout runttl wrapin wrapout hostname hostchange\n";<br />
}<br />
print IP "$time $ip[2] $ip[4] $sincelastin $sincelastout $curttlin $curttlout $runttl $lastrun[8] $lastrun[9] $hostname $lastrun[11]\n";<br />
}<br />
}<br />
<br />
## Now do data for WAN port<br />
<br />
my $curfile="$base"."/"."$today"."/"."$wanface";<br />
my ($lastrun, $curwanipt, $sincelastipt, $ttlipt, $insince, $runttlin, $outsince, $runttlout);<br />
if (!-e $curfile) {<br />
open WAN, ">> $curfile" or die $!;<br />
print WAN "timestamp ipt sysin sysout iptsince runipt insince outsince runttlin runttlout runttl wrapipt wrapin wrapout\n";<br />
if (-e "$base"."/"."$yesterday"."/"."$wanface") {<br />
my $lastfile = File::Tail->new(name => "$base"."/"."$yesterday"."/"."$wanface", tail => 1) or die $!;<br />
$lastrun = $lastfile -> read;<br />
my @resetday = split (/ /, $lastrun);<br />
@resetday[4..13] = (0) x 10;<br />
$lastrun = "@resetday";<br />
chomp $lastrun;<br />
} else {<br />
$lastrun = "0 0 0 0 0 0 0 0 0 0 0 0 0 0";<br />
chomp $lastrun;<br />
}<br />
} else {<br />
my $lastfile = File::Tail->new(name => "$base"."/"."$today"."/"."$wanface", tail => 1) or die $!;<br />
$lastrun = $lastfile -> read;<br />
chomp $lastrun;<br />
}<br />
my @ipt = qx($doipt -s -l $wanipt);<br />
foreach my $j (@ipt) {<br />
if ($j =~ /^\d/) {<br />
chomp $j;<br />
my @ipt = split(';', $j);<br />
$curwanipt =$ipt[2];<br />
last;<br />
}<br />
}<br />
open RX, "/sys/class/net/$wanface/statistics/rx_bytes" or die $!;<br />
open TX, "/sys/class/net/$wanface/statistics/tx_bytes" or die $!;<br />
my $sysin = <RX>;<br />
my $sysout = <TX>;<br />
chomp ($sysin, $sysout);<br />
my @lastrun = split(/ /, $lastrun);<br />
if ($lastrun[1] > $curwanipt) {<br />
$lastrun[11]++;<br />
# $sincelastipt = $lastrun[11]*$wrap+$curwanipt-$lastrun[5];<br />
$sincelastipt = $wrap+$curwanipt-$lastrun[1];<br />
$ttlipt = $lastrun[5]+$sincelastipt;<br />
} else {<br />
$sincelastipt = $curwanipt-$lastrun[1];<br />
$ttlipt = $sincelastipt+$lastrun[5];<br />
}<br />
if ($lastrun[2] > $sysin) {<br />
$lastrun[12]++;<br />
# $insince = $lastrun[12]*$wrap+$sysin-$lastrun[8];<br />
$insince = $wrap+$sysin-$lastrun[2];<br />
$runttlin = $lastrun[8]+$insince;<br />
} else {<br />
$insince = $sysin-$lastrun[2];<br />
$runttlin = $insince+$lastrun[8];<br />
}<br />
if ($lastrun[3] > $sysout) {<br />
$lastrun[13]++;<br />
# $outsince = $lastrun[13]*$wrap+$sysout-$lastrun[9];<br />
$outsince = $wrap+$sysout-$lastrun[3];<br />
$runttlout = $lastrun[9]+$outsince;<br />
} else {<br />
$outsince = $sysout-$lastrun[3];<br />
$runttlout = $outsince+$lastrun[9];<br />
}<br />
my $runttl = $runttlin+$runttlout;<br />
open WAN, ">>$curfile" or die $!;<br />
print WAN "$time $curwanipt $sysin $sysout $sincelastipt $ttlipt $insince $outsince $runttlin $runttlout $runttl $lastrun[11] $lastrun[12] $lastrun[13]\n";<br />
close WAN;<br />
<br />
## We should have a pretty comprehensive data set now, let's generate a report:<br />
<br />
if ( $hour == $rpthour && $min == $rptmin) {<br />
my ($wanfile, $mtdwan, $mtdlan, $runipt, $runsysin, $runsysout, $runsysttl, $mtdreadwan, $mtdreadlan, $day, $daysip, $todayipt, $todaysysin, $todaysysout, $todaysysttl, $mtdttlin, $mtdttlout, $mtdttl);<br />
my @mtdreadwan;<br />
my @mtdreadlan;<br />
my %daily=();<br />
my $rptfile = "$base"."/"."$today"."/"."Daily.rpt";<br />
opendir (DAYS,"$base"."/"."$month") or die "Can't open days $!";<br />
while (my $day = readdir(DAYS)) {<br />
next if $day =~ /^\D/;<br />
my $wanfile = File::Tail->new(name => "$base"."/"."$month"."/"."$day"."/"."$wanface", tail => 1);<br />
$mtdwan = $wanfile -> read; <br />
@mtdreadwan = split (/ /, $mtdwan);<br />
$runipt += $mtdreadwan[5];<br />
$runsysin += $mtdreadwan[8];<br />
$runsysout += $mtdreadwan[9];<br />
$runsysttl += $mtdreadwan[10];<br />
if ($day == $thisday) {<br />
$todayipt = $mtdreadwan[5];<br />
$todaysysin = $mtdreadwan[8];<br />
$todaysysout = $mtdreadwan[9];<br />
$todaysysttl = $mtdreadwan[10];<br />
}<br />
foreach my $i (@iptname) {<br />
next if (!-e "$base"."/"."$month"."/"."$day"."/"."$i");<br />
opendir (IPT, "$base"."/"."$month"."/"."$day"."/"."$i") or die "can't open $i days-iptname $!";<br />
while (my $daysip = readdir(IPT)) {<br />
next if $daysip =~ /^\D/;<br />
my $lanfile = File::Tail->new(name => "$base"."/"."$month"."/"."$day"."/"."$i"."/"."$daysip", tail => 1);<br />
$mtdlan = $lanfile -> read;<br />
@mtdreadlan = split (/ /, $mtdlan);<br />
$daily{$day}{$i}{$daysip}{ttlin} = $mtdreadlan[5];<br />
$daily{$day}{$i}{$daysip}{ttlout} = $mtdreadlan[6];<br />
$daily{$day}{$i}{$daysip}{ttl} = $mtdreadlan[7];<br />
$daily{$i}{$daysip}{mtdttlin} += $mtdreadlan[5];<br />
$daily{$i}{$daysip}{mtdttlout} += $mtdreadlan[6];<br />
$daily{$i}{$daysip}{mtdttl} += $mtdreadlan[7];<br />
$daily{$day}{$i}{$daysip}{devname} = $mtdreadlan[10]; <br />
$daily{$day}{$i}{$daysip}{devchange} = $mtdreadlan[11]; <br />
$daily{$i}{mtdin} += $daily{$day}{$i}{$daysip}{ttlin};<br />
$daily{$i}{mtdout} += $daily{$day}{$i}{$daysip}{ttlout};<br />
$daily{$i}{mtd} += $daily{$day}{$i}{$daysip}{ttl};<br />
if ( $day == $thisday ) {<br />
$daily{$i}{dailyttlin} += $mtdreadlan[5];<br />
$daily{$i}{dailyttlout} += $mtdreadlan[6];<br />
$daily{$i}{dailyttl} += $mtdreadlan[7];<br />
}<br />
} <br />
}<br />
}<br />
my $percentage = int($runsysttl/($maxbw*$mb*$mb*$mb)*100);<br />
open RPT, ">> $rptfile" or die $!;<br />
print RPT "****************************************************************************\n";<br />
print RPT "****************************************************************************\n";<br />
print RPT "** **\n";<br />
print RPT "** DAILY BANDWIDTH REPORT **\n";<br />
print RPT "** For day ending: $today **\n";<br />
print RPT "** Explanations and Documentation: **\n";<br />
print RPT "** http://help.computerisms.ca/index.php?title=Daily_Bandwidth_Report **\n";<br />
print RPT "** **\n";<br />
print RPT "****************************************************************************\n";<br />
print RPT "****************************************************************************\n";<br />
print RPT "\n";<br />
print RPT "\n";<br />
print RPT "============================================================================\n";<br />
print RPT "SUMMARY\n";<br />
print RPT "============================================================================\n";<br />
print RPT "\n";<br />
print RPT " Percentage of Allowed Bandwidth Used This Month: $percentage%\n";<br />
print RPT "\n";<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "", "Today", "", "This Month", "");<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "Raw Data on External Port", int($todaysysttl/$mb/$mb), "MB", int($runsysttl/$mb/$mb), "MB");<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "Accounted Data on External Port", int($todayipt/$mb/$mb), "MB", int($runipt/$mb/$mb), "MB");<br />
print RPT "\n";<br />
foreach my $i (@iptname) {<br />
if ( ! defined $daily{$i}{mtd} ) { <br />
$daily{$i}{mtd} = 0;<br />
}<br />
if ( ! defined $daily{$i}{dailyttl} ) {<br />
$daily{$i}{dailyttl} = 0;<br />
}<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "Accounted Data on $i", int($daily{$i}{dailyttl}/$mb/$mb), "MB", int($daily{$i}{mtd}/$mb/$mb), "MB");<br />
}<br />
print RPT "\n";<br />
print RPT "============================================================================\n";<br />
print RPT "INTERNET USAGE - DETAILED REPORT\n";<br />
print RPT "============================================================================\n";<br />
print RPT "\n";<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "", "Today", "", "This Month", "");<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "Raw Data - Download ", int($todaysysin/$mb/$mb), "MB", int($runsysin/$mb/$mb), "MB");<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "Raw Data - Upload", int($todaysysout/$mb/$mb), "MB", int($runsysout/$mb/$mb), "MB");<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "Raw Data - Total Usage", int($todaysysttl/$mb/$mb), "MB", int($runsysttl/$mb/$mb), "MB");<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "Accounted Data - Total Usage", int($todayipt/$mb/$mb), "MB", int($runipt/$mb/$mb), "MB");<br />
print RPT "\n";<br />
foreach my $i (@iptname) {<br />
my $uci = uc $i;<br />
print RPT "============================================================================\n";<br />
print RPT "$uci USAGE - DETAILED REPORT\n";<br />
print RPT "============================================================================\n";<br />
print RPT "\n";<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "", "Today", "", "This Month", "");<br />
for my $def ( $daily{$i}{dailyttlin}, $daily{$i}{mtdin}, $daily{$i}{dailyttlout}, $daily{$i}{mtdout}, $daily{$i}{dailyttl}, $daily{$i}{mtd} ) {<br />
if ( ! defined $def ) { <br />
$def = 0;<br />
}<br />
}<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "Accounted Data - Download ", int($daily{$i}{dailyttlout}/$mb/$mb), "MB", int($daily{$i}{mtdout}/$mb/$mb), "MB");<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "Accounted Data - Upload ", int($daily{$i}{dailyttlin}/$mb/$mb), "MB", int($daily{$i}{mtdin}/$mb/$mb), "MB");<br />
printf (RPT "%-36s%17s%3s%17s%3s\n", "Accounted Data - Total Usage ", int($daily{$i}{dailyttl}/$mb/$mb), "MB", int($daily{$i}{mtd}/$mb/$mb), "MB");<br />
print RPT "\n";<br />
}<br />
foreach my $i ( keys %{$daily{$thisday}} ) {<br />
my $uci = uc $i;<br />
print RPT "============================================================================\n";<br />
print RPT "$uci HOSTS - SUMMARY REPORT - VALUES IN MB\n";<br />
print RPT "============================================================================\n";<br />
print RPT "\n";<br />
printf (RPT "%-15s%6s%6s%6s%6s%6s%6s%19s%6s\n", "IP ADDR", "DAYDN", "DAYUP", "DAYTL", "MTDDN", "MTDUP", "MTDTL", "Last Seen Host ", "Host #");<br />
# if ( keys %{$daily{$thisday}{$i}} ) {<br />
foreach my $ips (sort ( keys %{$daily{$thisday}{$i}} ) ) {<br />
printf (RPT "%-15s%6s%6s%6s%6s%6s%6s%19s%6s\n", $ips, int($daily{$thisday}{$i}{$ips}{ttlout}/$mb/$mb), int($daily{$thisday}{$i}{$ips}{ttlin}/$mb/$mb), int($daily{$thisday}{$i}{$ips}{ttl}/$mb/$mb), int($daily{$i}{$ips}{mtdttlout}/$mb/$mb), int($daily{$i}{$ips}{mtdttlin}/$mb/$mb), int($daily{$i}{$ips}{mtdttl}/$mb/$mb), $daily{$thisday}{$i}{$ips}{devname}, $daily{$thisday}{$i}{$ips}{devchange});<br />
}<br />
# }<br />
}<br />
close (RPT);<br />
## Send the report<br />
<br />
open DRPT, "< $rptfile";<br />
my $dailyreport = do { local $/; <DRPT> };<br />
<br />
my $smtp = Net::SMTP->new ( "$smtpserver", Hello => "$mailhello" );<br />
$smtp->auth ("$smtpauthname","$smtpauthpass");<br />
$smtp->mail ("$mailfrom");<br />
$smtp->recipient ("$mailto", "$mailto2");<br />
$smtp->data();<br />
$smtp->datasend("From: $mailfrom\n");<br />
$smtp->datasend("To: $mailto, $mailto2\n");<br />
$smtp->datasend("Subject: Daily BWRprt - Monthly usage is $percentage %\n");<br />
$smtp->datasend("Date: $date\n");<br />
$smtp->datasend("\n");<br />
$smtp->datasend("$dailyreport\n");<br />
$smtp->dataend();<br />
$smtp->quit;<br />
}<br />
</pre></div>
Bob