| 1 | #!@PERL@
|
|---|
| 2 | #
|
|---|
| 3 | # Prints info on all smb responding machines on a subnet.
|
|---|
| 4 | # This script needs to be run on a machine without nmbd running and be
|
|---|
| 5 | # run as root to get correct info from WIN95 clients.
|
|---|
| 6 | #
|
|---|
| 7 | # syntax:
|
|---|
| 8 | # findsmb [-d|-D] [-r] [subnet broadcast address]
|
|---|
| 9 | #
|
|---|
| 10 | # with no agrument it will list machines on the current subnet
|
|---|
| 11 | #
|
|---|
| 12 | # There will be a "+" in front of the workgroup name for machines that are
|
|---|
| 13 | # local master browsers for that workgroup. There will be an "*" in front
|
|---|
| 14 | # of the workgroup name for machines that are the domain master browser for
|
|---|
| 15 | # that workgroup.
|
|---|
| 16 | #
|
|---|
| 17 | # Options:
|
|---|
| 18 | #
|
|---|
| 19 | # -d|-D enable debug
|
|---|
| 20 | # -r add -r option to nmblookup when finding netbios name
|
|---|
| 21 | #
|
|---|
| 22 |
|
|---|
| 23 | $SAMBABIN = "@prefix@/bin";
|
|---|
| 24 |
|
|---|
| 25 | for ($i = 0; $i < 2; $i++) { # test for -d and -r options
|
|---|
| 26 | $_ = shift;
|
|---|
| 27 | if (m/-d|-D/) {
|
|---|
| 28 | $DEBUG = 1;
|
|---|
| 29 | } elsif (m/-r/) {
|
|---|
| 30 | $R_OPTION = "-r";
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | if ($_) { # set broadcast address if it was specified
|
|---|
| 35 | $BCAST = "-B $_";
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | ######################################################################
|
|---|
| 40 | # do numeric sort on last field of IP address
|
|---|
| 41 | sub ipsort
|
|---|
| 42 | {
|
|---|
| 43 | @t1 = split(/\./,$a);
|
|---|
| 44 | @t2 = split(/\./,$b);
|
|---|
| 45 | @t1[3] <=> @t2[3];
|
|---|
| 46 | }
|
|---|
| 47 | ######################################################################
|
|---|
| 48 |
|
|---|
| 49 | # look for all machines that respond to a name lookup
|
|---|
| 50 |
|
|---|
| 51 | open(NMBLOOKUP,"$SAMBABIN/nmblookup $BCAST '*' --debuglevel=0|") ||
|
|---|
| 52 | die("Can't run nmblookup '*'.\n");
|
|---|
| 53 |
|
|---|
| 54 | # get rid of all lines that are not a response IP address,
|
|---|
| 55 | # strip everything but IP address and sort by last field in address
|
|---|
| 56 |
|
|---|
| 57 | @ipaddrs = sort ipsort grep(s/ \*<00>.*$//,<NMBLOOKUP>);
|
|---|
| 58 |
|
|---|
| 59 | # print header info
|
|---|
| 60 | print "\n *=DMB\n";
|
|---|
| 61 | print " +=LMB\n";
|
|---|
| 62 | print "IP ADDR NETBIOS NAME WORKGROUP/OS/VERSION $BCAST\n";
|
|---|
| 63 | print "---------------------------------------------------------------------\n";
|
|---|
| 64 |
|
|---|
| 65 | foreach $ip (@ipaddrs) # loop through each IP address found
|
|---|
| 66 | {
|
|---|
| 67 | $ip =~ s/\n//; # strip newline from IP address
|
|---|
| 68 |
|
|---|
|
|---|