Many times we need a way to fetch system configuration, or to get some of the interface statistics, or maybe we want to get pre-shared key retrieved...
We also want to make this request using secure network connection, such as HTTPS.
This Perl script will show you how to retrieve "running-configuration" from the device. We are doing this using "more system:running-config" command, which will output our preshared keys.
use strict;
use warnings;
use LWP;
my $url = 'https://firewall01/admin/exec/more%20system:running-config';
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $url);
$req->authorization_basic('MyUsername', 'MyPassword');
my $content = $ua->request($req)->as_string;
print "Configuration file:\n";
print $content;
This will work on FWSM, PIX, ASA, or ever any other IOS devices...
Sometimes you will need to execute several commands in a row, such as:
FWSM# changeto system FWSM# show resource acl-partition
In order to accomplish that we will separate each command by the "/" (slash).
#!/usr/local/bin/perl
use strict;
use warnings;
use LWP;
my $url = 'https://firewall01/admin/exec/changeto%20context%20system/show%20resource%20acl-partition';
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $url);
$req->authorization_basic('user', 'password');
my $content = $ua->request($req)->as_string;
print "Command Output:\n";
print $content;
We have 3 guests and no members online