+ if ( !defined($netBiosHostName) ) {
+ print(STDERR "NetBiosInfoGet: failed: can't parse return string\n")
+ if ( $bpc->{verbose} );
+ return;
+ }
+ $netBiosHostName = lc($netBiosHostName);
+ $netBiosUserName = lc($netBiosUserName);
+ print(STDERR "NetBiosInfoGet: success, returning host $netBiosHostName,"
+ . " user $netBiosUserName\n") if ( $bpc->{verbose} );
+ return ($netBiosHostName, $netBiosUserName);
+}
+
+#
+# Given a NetBios name lookup the IP address via NetBios.
+# In the case of a host returning multiple interfaces we
+# return the first IP address that matches the subnet mask.
+# If none match the subnet mask (or nmblookup doesn't print
+# the subnet mask) then just the first IP address is returned.
+#
+sub NetBiosHostIPFind
+{
+ my($bpc, $host) = @_;
+ my($netBiosHostName, $netBiosUserName);
+ my($s, $nmbCmd, $subnet, $ipAddr, $firstIpAddr);
+
+ #
+ # Skip NetBios lookup if NmbLookupFindHostCmd is emtpy
+ #
+ if ( $bpc->{Conf}{NmbLookupFindHostCmd} eq "" ) {
+ print(STDERR "NetBiosHostIPFind: return $host because"
+ . " \$Conf{NmbLookupFindHostCmd} is empty\n")
+ if ( $bpc->{verbose} );
+ return $host;
+ }
+
+ my $args = {
+ nmbLookupPath => $bpc->{Conf}{NmbLookupPath},
+ host => $host,
+ };
+ $nmbCmd = $bpc->cmdVarSubstitute($bpc->{Conf}{NmbLookupFindHostCmd}, $args);
+ foreach my $resp ( split(/[\n\r]+/, $bpc->cmdSystemOrEval($nmbCmd, undef,
+ $args) ) ) {
+ if ( $resp =~ /querying\s+\Q$host\E\s+on\s+(\d+\.\d+\.\d+\.\d+)/i ) {
+ $subnet = $1;
+ $subnet = $1 if ( $subnet =~ /^(.*?)(\.255)+$/ );
+ } elsif ( $resp =~ /^\s*(\d+\.\d+\.\d+\.\d+)\s+\Q$host/ ) {
+ my $ip = $1;
+ $firstIpAddr = $ip if ( !defined($firstIpAddr) );
+ $ipAddr = $ip if ( !defined($ipAddr) && $ip =~ /^\Q$subnet/ );
+ }
+ }
+ $ipAddr = $firstIpAddr if ( !defined($ipAddr) );
+ if ( defined($ipAddr) ) {
+ print(STDERR "NetBiosHostIPFind: found IP address $ipAddr for"
+ . " host $host\n") if ( $bpc->{verbose} );
+ return $ipAddr;
+ } else {
+ print(STDERR "NetBiosHostIPFind: couldn't find IP address for"
+ . " host $host\n") if ( $bpc->{verbose} );
+ return;
+ }