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'};
20 => where { m{\d+(/\d+)+} }
21 => message { 'invalid port' };
23 has 'ip' => ( is => 'rw', isa => 'IPAddr' );
24 has 'port' => ( is => 'rw', isa => 'Port' );
33 return $telnet->{$ip} if exists $telnet->{$ip};
35 my $t = Net::Telnet->new( Timeout => 10, Prompt => '/#/' );
37 $t->dump_log('/tmp/log') if $ENV{DEBUG};
43 $t->waitfor('/Login:/');
45 $t->waitfor('/Password:/');
49 $t->waitfor('/Please input password:/');
55 return $telnet->{$ip} = $t;
59 my ($self,$command) = @_;
61 $command .= ' ' . $self->port;
63 my $t = $self->telnet;
70 my($prematch, $match) = $t->waitfor('/(Press any key to continue \(Q to quit\)|#)/');
72 last if $match eq '#';
76 warn "## out = [$out]" if $ENV{DEBUG};
79 foreach my $line ( split(/[\n\r]+/, $out) ) {
80 warn "# $line\n" if $ENV{DEBUG};
81 if ( $line =~ m/^(\S+.*?)\s+:\s+(\S+.*)$/ ) {
85 warn "## $n = $v\n" if $ENV{DEBUG};
90 warn "## ", $self->ip, " $command ",dump $hash;
99 my $port = $self->port;
101 warn "# hash $ip $port";
106 foreach my $name (@_) {
107 # warn "# copy $name ", dump( $row ),$/;
108 $row->{$name} = $hash->{$name};
112 $hash = $self->command('show interface');
119 $hash = $self->command('show adsl status');
124 $hash = $self->command('show adsl physical');
140 warn "# row = ",dump $row;
150 my $t = $telnet->{$ip} || die "no $ip telnet in ",dump($telnet);
161 warn "# DESTROY telnet = ",dump( keys %$telnet );
162 $self->logout($_) foreach keys %$telnet;