Ok I got it going somehow, now it uses temp files but it works :-)
Here it is my first prog :-).
#!/usr/bin/perl -w
use Net::SNMP;
#use strict;
use warnings;
use diagnostics;
open IPFILE, "ipfile.txt" or die "Can't get IPs - $!\n";
my $community = 'public';
my $ifIndex = '1.3.6.1.2.1.47.1.1.1.1.6'; #1.3.6.1.2.1.2.2.1.1
+ 1.3.6.1.2.1.47.1.1.1.1.12
my $ifDescr = '1.3.6.1.2.1.47.1.1.1.1.11'; #1.3.6.1.2.1.47.1.1.1.1.
+13
my $ifDescr2 = '1.3.6.1.2.1.47.1.1.1.1.2'; #1.3.6.1.2.1.47.1.1.1.1.
+13
while ( my $ip = <IPFILE> )
{
chomp $ip;
print "Got: $ip\n";
+
my ( $session, $error ) = Net::SNMP->session(
-hostname => $ip,
-community => $community,
-port => 161
);
my $response;
if ( defined( $response = $session->get_table($ifIndex) ) )
{
foreach my $index ( values %{$response} ) #values
{
my $this_desc = "$ifDescr.$index";
my $description;
if ( defined( $description = $session->get_request($this_d
+esc) ) )
{
my @serial = values %{$description};
open OUTPUT1, ">>serlist.txt";
print OUTPUT1 @serial, "\n";
close OUTPUT1;
}
}
foreach my $index ( values %{$response} ) #values
{
my $this_desc = "$ifDescr2.$index";
my $description2;
if ( defined( $description2 = $session->get_request($this_
+desc) ) )
{
my @desc = values %{$description2};
open OUTPUT2, ">>desclist.txt";
print OUTPUT2 @desc, "\n";
close OUTPUT2;
}
}
open(OUT, "serlist.txt");
open(OUT2, "desclist.txt");
my @outlist;
while (<OUT>)
{
my %hash;
my @temp = split(/;/,$_);
$hash{'file1'} = $temp[0];
$hash{'file2'} = <OUT2>;
#Return entfernen
foreach (values %hash)
{
$_ =~ s/\n//g;
}
push(@outlist,\%hash);
}
close(OUT);
open FINOUT, ">>finallist.txt";
print FINOUT "$ip\n";
foreach my $hashref (@outlist)
{
print FINOUT "$hashref->{'file1'};$hashref->{'file2'}\n";
}
print FINOUT "\n";
close FINOUT;
}
$session->close();
}
... maybe you have an idea to do it without those temps.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|