8 use Data::Dump qw(dump);
10 use Moose::Util::TypeConstraints;
11 use Regexp::Common qw(net);
15 => where {/^$RE{net}{IPv4}$/}
16 => message { 'invalid IP address'};
18 has 'ip' => ( is => 'rw', isa => 'IPAddr' );
27 return $telnet->{$ip} if exists $telnet->{$ip};
29 my $t = Net::Telnet->new( Timeout => 10, Prompt => '/#/' );
31 $t->dump_log('/tmp/log') if $ENV{DEBUG};
37 $t->waitfor('/Login:/');
39 $t->waitfor('/Password:/');
43 $t->waitfor('/Please input password:/');
49 return $telnet->{$ip} = $t;
53 my ($self,$command) = @_;
55 $command .= ' ' . $self->{port};
57 my $t = $self->telnet;
64 my($prematch, $match) = $t->waitfor('/(Press any key to continue \(Q to quit\)|#)/');
66 last if $match eq '#';
70 warn "## out = [$out]" if $ENV{DEBUG};
73 foreach my $line ( split(/[\n\r]+/, $out) ) {
74 warn "# $line\n" if $ENV{DEBUG};
75 if ( $line =~ m/^(\S+.*?)\s+:\s+(\S+.*)$/ ) {
79 warn "## $n = $v\n" if $ENV{DEBUG};
84 warn "## ", $self->ip, " $command ",dump $hash;
90 my ($self,$port) = @_;
93 $self->{port} = $port;
95 warn "# hash $ip $port";
100 foreach my $name (@_) {
101 # warn "# copy $name ", dump( $row ),$/;
102 $row->{$name} = $hash->{$name};
106 $hash = $self->command('show interface');
113 $hash = $self->command('show adsl status');
118 $hash = $self->command('show adsl physical');
134 warn "# row = ",dump $row if $ENV{DEBUG};
144 my $t = $telnet->{$ip} || die "no $ip telnet in ",dump($telnet);
155 warn "# DESTROY telnet = ",dump( keys %$telnet );
156 $self->logout($_) foreach keys %$telnet;