Forum Discussion

Sunny_Aujla_888's avatar
Sunny_Aujla_888
Icon for Nimbostratus rankNimbostratus
Apr 08, 2011

Get Admin IP address with SNMP

Hi,

 

 

Is there a way i can obtain the _admin_ IP address through snmp?

 

 

 

When i enter this command

 

 

 

snmpwalk -v 2c -c .1.3.6.1.4.1.3375.2.1.2.1.1.2.1

 

SNMPv2-SMI::enterprises.3375.2.1.2.1.1.2.1.1.1.4. = INTEGER: 1

 

SNMPv2-SMI::enterprises.3375.2.1.2.1.1.2.1.2.1.4. = Hex-STRING: AC 1E 91 0A

 

SNMPv2-SMI::enterprises.3375.2.1.2.1.1.2.1.3.1.4. = INTEGER: 1

 

SNMPv2-SMI::enterprises.3375.2.1.2.1.1.2.1.4.1.4. = Hex-STRING: FF FF FF 00

 

 

 

 

But i do not know how i can interpret this in PERL? Any ideas where i could start?

 

  • I've got a work around this. I just used the following way without SNMP.

    !/usr/bin/perl -w

    use Socket;
    use strict;
     
    my $host_name = hostname($ARGV[0]);
    print "$ARGV[0] resolves to $host_name\n";
     
    sub hostname {
     
      my (@bytes, @octets,
        $packedaddr,
        $raw_addr,
        $host_name,
        $ip
      );
     
      if($_[0] =~ /[a-zA-Z]/g) {
        $raw_addr = (gethostbyname($_[0]))[4];
        @octets = unpack("C4", $raw_addr);
        $host_name = join(".", @octets);
      } else {
        @bytes = split(/\./, $_[0]);
        $packedaddr = pack("C4",@bytes);
        $host_name = (gethostbyaddr($packedaddr, 2))[0];
      }
     
      return($host_name);
    }

  • I think the IP that the hostname resolves to is configurable and could vary by unit. You could run this command to get the mgmt IP:

     

     

    b mgmt|cut -f 2 -d " "

     

     

    Aaron