summaryrefslogtreecommitdiff
path: root/source/script
diff options
context:
space:
mode:
Diffstat (limited to 'source/script')
-rw-r--r--source/script/.cvsignore1
-rwxr-xr-xsource/script/findsmb.in118
2 files changed, 64 insertions, 55 deletions
diff --git a/source/script/.cvsignore b/source/script/.cvsignore
index e69de29bb2d..7a8114ecd73 100644
--- a/source/script/.cvsignore
+++ b/source/script/.cvsignore
@@ -0,0 +1 @@
+findsmb
diff --git a/source/script/findsmb.in b/source/script/findsmb.in
index d2aa94591b7..e9bb247da0d 100755
--- a/source/script/findsmb.in
+++ b/source/script/findsmb.in
@@ -47,7 +47,9 @@ open(NMBLOOKUP,"$SAMBABIN/nmblookup $BCAST '*'|") ||
# print header info
-print "\nIP ADDR NETBIOS NAME WORKGROUP/OS/VERSION $BCAST\n";
+print "\n *=DMB\n";
+print " +=LMB\n";
+print "IP ADDR NETBIOS NAME WORKGROUP/OS/VERSION $BCAST\n";
print "---------------------------------------------------------------------\n";
foreach $ip (@ipaddrs) # loop through each IP address found
@@ -61,85 +63,91 @@ foreach $ip (@ipaddrs) # loop through each IP address found
@nmblookup = <NMBLOOKUP>;
close NMBLOOKUP;
-# get the first <00> name
+# get the first non group <00> name
- @name = grep(/<00>/,@nmblookup);
+ @name = grep(/<00> - /,@nmblookup);
$_ = @name[0];
- if ($_) { # we have a netbios name
- if (/GROUP/) { # is it a group name
- ($name, $aliases, $type, $length, @addresses) =
- gethostbyaddr(pack('C4',split('\.',$ip)),2);
- if (! $name) { # could not get name
- $name = "unknown nis name";
- }
- } else {
+ if (not $_) {
+# try without the -r option
+ open(NMBLOOKUP,"$SAMBABIN/nmblookup -A $ip|") ||
+ die("Can't get nmb name list.\n");
+ @nmblookup = <NMBLOOKUP>;
+ close NMBLOOKUP;
+ @name = grep(/<00> - /,@nmblookup);
+ $_ = @name[0];
+ }
# The Netbios name can contain lot of characters also '<' '>'
-# and spaces. The follwing cure inside name space but not
+# and spaces. The follwing cures embedded space but not
# names starting or ending with spaces
- /(.{1,15})\s+<00>\s+/;
- $name = $1;
+ /(.{1,15})\s+<00>\s+/;
+ $name = $1;
+
+ if (not $name) { # no netbios name found
+# try getting the host name
+ ($name, $aliases, $type, $length, @addresses) =
+ gethostbyaddr(pack('C4',split('\.',$ip)),2);
+ if (! $name) { # could not get name
+ $name = "unknown name";
}
+# truncate name to 15 characters
+ if (length($name) > 15) {
+ $name = substr($name,0,15);
+ }
+# do an smbclient command on the ip address
+
+ open(SMB,"$SAMBABIN/smbclient -N -L '$ip' -I $ip -U% |") ||
+ die("Can't do smbclient command.\n");
+ @smb = <SMB>;
+ close SMB;
+ } else { # netbios name found
# do an smbclient command on the netbios name.
- open(SMB,"$SAMBABIN/smbclient -N -L $name -I $ip -U% |") ||
+ open(SMB,"$SAMBABIN/smbclient -N -L '$name' -I $ip -U% |") ||
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;
- }
+ }
+ 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
+ @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)
+ } 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 ($_) {
+ @name = grep(/<00> - <GROUP>/,@nmblookup);
+ $_ = @name[0];
+ if ($_) {
# Same as before for space and characters
- /(.{1,15})\s+<00>\s+/;
- $_ = "[$1]";
- } else {
- $_ = "Unknown Workgroup";
- }
+ /(.{1,15})\s+<00>\s+/;
+ $_ = "[$1]";
+ } else {
+ $_ = "Unknown Workgroup";
}
+ }
# see if machine registered a local master browser name
- if (grep(/<1d>/,@nmblookup)) {
- $master = '+'; # indicate local master browser
- if (grep(/<1b>/,@nmblookup)) { # how about domain master browser?
- $master = '*'; # indicate domain master browser
- }
- } else {
- $master = ' '; # not a browse master
+ if (grep(/<1d>/,@nmblookup)) {
+ $master = '+'; # indicate local master browser
+ if (grep(/<1b>/,@nmblookup)) { # how about domain master browser?
+ $master = '*'; # indicate domain master browser
}
+ } else {
+ $master = ' '; # not a browse master
+ }
# line up info in 3 columns
- print "$ip".' 'x(16-length($ip))."$name".' 'x(14-length($name))."$master"."$_\n";
+ print "$ip".' 'x(16-length($ip))."$name".' 'x(16-length($name))."$master"."$_\n";
- } else { # no netbios name found
-# try getting the host name
- ($name, $aliases, $type, $length, @addresses) =
- gethostbyaddr(pack('C4',split('\.',$ip)),2);
- if (! $name) { # could not get name
- $name = "unknown nis name";
- }
- if ($DEBUG) { # if -d flag print results of nmblookup
- print "===============================================================\n";
- print @nmblookup;
- }
- print "$ip".' 'x(16-length($ip))."$name\n";
- }
}