Sakura
Sakura

Reputation: 969

Perl: Unable to check validity of hostname for Net::Appliance::Session

When I tried to pass an invalid hostname, the code will get into an infinite loop.

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

Is there a way to overcome this bug?

EDIT: Here's my full code: I use the subroutine to download the config file of my network device. When I pass in an invalid IP address in download_config, it will get into an infinite loop.

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;
}

Upvotes: 1

Views: 508

Answers (2)

Sakura
Sakura

Reputation: 969

The developer has fixed the bug.

Upvotes: 1

user1126070
user1126070

Reputation: 5069

Are you sure?

Are you tried this example code with your host name?

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

If yes, you could create an RT ticket or you could try to contact the author.

I have chacked the code, and did not found anything (too) nasty.

Regards,

Upvotes: 0

Related Questions