#!/usr/bin/perl -w
use strict;

###########################################################################
# (c) 2005 Brett T. Warden
# http://www.wgz.org/bwarden/
#
# License:
# Perl Artistic License
# http://www.perl.com/language/misc/Artistic.html
#
# Other licensing arrangements available upon request.
#
# Note specifically:
#  THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
#  MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
###########################################################################

use Net::Netrc;
use LWP::Simple;
use Template::Extract;
use Data::Dumper;

my $machine = shift(@ARGV) || 'vapor.gue.st.wgz.org'; 
my $auth = Net::Netrc->lookup($machine, 'admin');
my $login = $auth->login();
my $password = $auth->password();

my $obj = Template::Extract->new;

my $template = << '.';
<table[% ... %]>
[% /\s*/ %]<tr[% ... %]</tr>
[% FOREACH host %]
[% /\s*/ %]<tr[% ... %]><td[% ... %]><font[% ... %]>[% /\s*/ %][% name %][% /\s*/ %]</font></td><td[% ... %]><font[% ... %]>[% mac %]</font></td><td[% ... %]><img[% ... %]><img[% ... %]></td></tr>
[% ... %]
[% END %]</table>
.

my $document = get('http://'.$login.':'.$password.'@'.$machine.'/adv_filters_mac.html');

my $clients = $obj->extract($template, $document);

#print Data::Dumper::Dumper(
#				$clients
#			   );

print sprintf("%-20s\t%-17s\n", 'Name', 'MAC');
for my $row (@{$clients->{host}}) {
#	print Data::Dumper::Dumper($row);
	print sprintf("%-20s\t%-17s\n", $row->{name}, $row->{mac});
}
