Check the device IP address and node name
This section of the SNMP GET access example Perl script checks for the device's IP address and node name. Use this part of the example script as a guide to writing code that checks for a device's IP address and node name in client/server Perl scripts that retrieve SNMP information.
The SNMP GET access example Perl script checks for a device's IP address and node name as follows:
my $nodeIP = $node; 1
if ($node !~ /^\d+\.\d+\.\d+\.\d+$/) { 2
$nodeIP = gethostbyname($node); 3
$nodeIP = inet_ntoa($nodeIP) if (defined $nodeIP) or
die "Can't find IP address for '$node'"; 4
}
The following list explains specific numbered items in the previously listed section of the SNMP GET access Perl script example:
- Assigns the value stored in the
my $nodevariable to themy $nodeIPvariable. Themy $nodevariable was set after the call to theRIV::Paramconstructor.See RIV::Param Constructor for more information.
- Determines if an IP address or node (host) name was specified.
- Gets the IP address from the node name by calling the
gethostbynameandinet_ntoafunctions. - If the
definedfunction verifies that the value in$nodeIPisundef, consider this a fatal error and call thediefunction. Thediefunction prints out an appropriate message (in this case, that the IP address for this device cannot be found) to the standard error stream.