Perl:无法检查Net :: Appliance :: Session的主机名的有效性

时间:2012-06-01 02:48:19

标签: perl ssh module cisco

当我尝试传递无效的主机名时,代码将进入无限循环。

my $s = Net::Appliance::Session->new({
personality => 'ios',
transport => 'SSH',
host => $ip
});

有没有办法克服这个错误?

编辑: 这是我的完整代码: 我使用子程序下载我的网络设备的配置文件。当我在download_config中传入一个无效的IP地址时,它将进入无限循环。

sub download_config
{
    my ($ip) = @_;
    my $s = Net::Appliance::Session->new({
     personality => 'ios',
     transport => 'SSH',
     host => $ip,
     Timeout => 1
    });

$s->set_global_log_at('debug'); # maximum debugging

    eval {
        $s->connect({ username => $username, password => $password });
        $s->begin_privileged({ password => $enable_password });

        #get hostname to set the file name
        $hostname_result = $s->cmd('sh run | inc hostname');
        $hostname_result =~ m/hostname (.*)/;
        $hostname = $1;

        #download the file
        my @running_config = $s->cmd('sh run');
        @running_config = @running_config[ 2 .. (@running_config -1)];#remove header and footer of the file
        open(FH, "> temp/".$hostname.".txt") or die("Cannot open config file : $!");
        print FH @running_config;
        close FH;
        $s->end_privileged;
    };
    if ($@) {
    #when the login details are wrong
        print redirect('../../na/unauthorised.html');
    }
    $s->close;
}

2 个答案:

答案 0 :(得分:1)

开发人员修复了错误。

答案 1 :(得分:0)

你确定吗?

您是否尝试过使用主机名的示例代码?

http://cpansearch.perl.org/src/OLIVER/Net-Appliance-Session-3.120560/examples/example-1.pl

如果是,您可以创建RT票证,或者您可以尝试联系作者。

我已经查了代码,并没有发现任何(太)讨厌。

此致