This repository has been archived by the owner on Aug 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRouter.pm
58 lines (46 loc) · 1.6 KB
/
Router.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
#==============================================================================
# ARCHIVO: Router.pm
# AUTOR: Victor Rodriguez - victor <at> vrdominguez.es
# DESCRIPCION: Clase base para los comandos del contestador Raspberry Pi que
# acceden al router Huawei HG556a de vodafone
#==============================================================================
package Router;
use strict;
use Net::Telnet;
sub new {
my $usuario = $_[1] || die(__PACKAGE__.'->new() ERROR: Falta usuario de acceso al router');
my $password = $_[2] || die(__PACKAGE__.'->new() ERROR: Falta clave de acceso al router');
my $ip_router = $_[3] || '192.168.0.1'; # IP por defecto del router
my $prompt = $_[4] || '/VFMN0001222915>/'; # Prompt del router
return bless({
usuario => $usuario,
password => $password,
ip => $ip_router,
prompt => $prompt,
conexion => undef
});
}
sub conectar {
my $self = $_[0];
unless( $self->{conexion} ) {
$self->{conexion} = Net::Telnet->new(Host => $self->{ip}, Prompt=>$self->{prompt})
|| die(__PACKAGE__.'->conectar() ERROR: No se ha podido establercer la conexion con el router');
$self->{conexion}->login($self->{usuario}, $self->{password});
}
return $self;
}
sub ejecutarComando {
my $self = $_[0];
my $comando = $_[1] || die(__PACKAGE__.'->ejecutarComando ERROR: Comando no definido');
my $salida = undef;
eval {
$salida = join("\n", $self->conectar()->{conexion}->cmd($comando));
chomp($salida);
};
if ($@) {
die(__PACKAGE__.'->ejecutarComando() ERROR: FAllo en ejecucion de comando. Detalles: '.$@);
}
return $salida;
}
1;