fix some problems with the findsmb script due to changes in smbclient & nmblookup
authorGerald Carter <jerry@samba.org>
Fri, 5 Sep 2003 13:07:41 +0000 (13:07 +0000)
committerGerald Carter <jerry@samba.org>
Fri, 5 Sep 2003 13:07:41 +0000 (13:07 +0000)
(This used to be commit 50bb063f3ba0ce0f336bd9f1af3090839ee7b118)

source3/script/findsmb.in

index 6276bd3f3921bed6a45e75cdb324b166330a8f0a..5a8e86d722ed55cc4a8d2977f30155ec084189c3 100755 (executable)
@@ -44,7 +44,7 @@ sub ipsort                    # do numeric sort on last field of IP address
 
 # look for all machines that respond to a name lookup
 
-open(NMBLOOKUP,"$SAMBABIN/nmblookup $BCAST '*'|") || 
+open(NMBLOOKUP,"$SAMBABIN/nmblookup $BCAST '*' --debuglevel=0|") || 
   die("Can't run nmblookup '*'.\n");
 
 # get rid of all lines that are not a response IP address,
@@ -63,7 +63,7 @@ foreach $ip (@ipaddrs)                # loop through each IP address found
 
 # find the netbios names registered by each machine
 
-  open(NMBLOOKUP,"$SAMBABIN/nmblookup $R_OPTION -A $ip|") || 
+  open(NMBLOOKUP,"$SAMBABIN/nmblookup $R_OPTION -A $ip --debuglevel=0|") || 
        die("Can't get nmb name list.\n");
   @nmblookup = <NMBLOOKUP>;
   close NMBLOOKUP;
@@ -89,35 +89,37 @@ foreach $ip (@ipaddrs)              # loop through each IP address found
 
 # do an smbclient command on the netbios name.
 
-    open(SMB,"$SAMBABIN/smbclient -N -L $name -I $ip -U% |") ||
-       die("Can't do smbclient command.\n");
-    @smb = <SMB>;
-    close SMB;
+    if ( "$name" ) {
+      open(SMB,"$SAMBABIN/smbclient -L $name -I $ip -N --debuglevel=1 2>&1 |") ||
+         die("Can't do smbclient command.\n");
+      @smb = <SMB>;
+      close SMB;
 
-    if ($DEBUG) {              # if -d flag print results of nmblookup and smbclient
-      print "===============================================================\n";
-      print @nmblookup;
-      print @smb;
-    }
-
-# look for the OS= string
-
-    @info = grep(/OS=/,@smb);
-    $_ = @info[0];
-    if ($_) {                          # we found response
-      s/Domain=|OS=|Server=|\n//g;     # strip out descriptions to make line shorter
-
-    } else {                           # no OS= string in response (WIN95 client)
+      if ($DEBUG) {            # if -d flag print results of nmblookup and smbclient
+        print "===============================================================\n";
+        #print @nmblookup;
+        print @smb;
+      }
 
-# for WIN95 clients get workgroup name from nmblookup response
-      @name = grep(/<00> - <GROUP>/,@nmblookup);
-      $_ = @name[0];
-      if ($_) {
-# Same as before for space and characters
-        /(.{1,15})\s+<00>\s+/;
-        $_ = "[$1]";
-      } else {
-       $_ = "Unknown Workgroup";
+      # look for the OS= string
+
+      @info = grep(/OS=/,@smb);
+      $_ = @info[0];
+      if ($_) {                                # we found response
+        s/Domain=|OS=|Server=|\n//g;   # strip out descriptions to make line shorter
+
+      } else {                         # no OS= string in response (WIN95 client)
+
+        # for WIN95 clients get workgroup name from nmblookup response
+        @name = grep(/<00> - <GROUP>/,@nmblookup);
+        $_ = @name[0];
+        if ($_) {
+          # Same as before for space and characters
+          /(.{1,15})\s+<00>\s+/;
+          $_ = "[$1]";
+        } else {
+         $_ = "Unknown Workgroup";
+        }
       }
     }