ok here is a short form:
#open ipfile
open IPFILE, "ipfile2.txt" or die "Can't get IPs - $!\n";
open NAMES, "namefile2.txt" or die "Can't get IPs - $!\n";
open ERASER, ">finallist.txt";
close ERASER;
+
#Sets knots und community
my $community = 'public';
my $ifSer = '.1.3.6.1.2.1.47.1.1.1.1.11';
my $ifPart = '.1.3.6.1.2.1.47.1.1.1.1.13';
while ( $ip = <IPFILE>, $name = <NAMES> )
{
my @final1;
chomp $ip;
chomp $name;
$name =~ s/\.bc\.de\.bic$//;
print "Got: $ip\n";
+
#open session
my ( $s, $e ) = Net::SNMP->session(
-hostname => $ip,
-community => $community,
-port => 161
);
if (!defined($s))
{
print ("Falsch nix is!");
}
-------------------------------------------------------
Ok here it gets interesting:
my @args = (
-varbindlist => [$ifSer]
);
my @args2 = (
-varbindlist => [$ifPart]
);
if ($s->version == SNMP_VERSION_1)
{
while (defined($s->get_next_request(@args)))
{
$_ = (keys(%{$s->var_bind_list}))[0];
if (!oid_base_match($ifSer, $_)) { last; }
$response=($s->var_bind_list->{$_});
@final1 = $response;
@args = (-varbindlist => [$_]);
}
while (defined($s->get_next_request(@args2)))
{
$_ = (keys(%{$s->var_bind_list}))[0];
if (!oid_base_match($ifPart, $_)) { last; }
$response2 = ($s->var_bind_list->{$_});
@final2 = $response2;
@args2 = (-varbindlist => [$_]);
}
}
-------------------------------------------------------
Here is the print that must work at the end:
#@final2 = grep { $_ ne "" } $response2;
open OUTPUT, ">>finallist.txt";
for my $i (0 .. $#final1) { print "$ip;$name;$final1[$i];$final2[
+$i]\n" }
close OUTPUT;
print $ip;print $name;
# Let the user know about any errors
#if ($s->error() ne '') {
# _exit($s->error());
#}
# Close the session
#$s->close();
}
exit 0;
And the result should be :
ip1;name1;serial1;part1
ip1;name1;serial2;part2
ip2;name2;serial1;part1
........
the ip and the name is already ok I only need the serial (final1) and the part (final2) thing to work
-
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.