#!/usr/local/bin/perl use strict; use Getopt::Long; use vars qw/@opt_name @opt_ip @opt_sub $opt_h $opt_all/; my $path = '/usr/local/samba/var/locks/'; # NetBIOS Suffixes (16th Character of the NetBIOS Name) my %wins_status = ( 'Workstation Service' => 0x00, 'Messenger Service' => 0x01, 'Messenger Service' => 0x03, 'RAS Server Service' => 0x06, 'NetDDE Service' => 0x1F, 'File Server Service' => 0x20, 'RAS Client Service' => 0x21, 'Microsoft Exchange Interchange(MSMail Connector)'=> 0x22, 'Microsoft Exchange Store' => 0x23, 'Microsoft Exchange Directory' => 0x24, 'Modem Sharing Server Service' => 0x30, 'Modem Sharing Client Service' => 0x31, 'SMS Clients Remote Control' => 0x43, 'SMS Administrators Remote Control Tool' => 0x44, 'SMS Clients Remote Chat' => 0x45, 'SMS Clients Remote Transfer' => 0x46, 'DEC Pathworks TCPIP service on Windows NT' => 0x4C, 'DEC Pathworks TCPIP service on Windows NT' => 0x52, 'Microsoft Exchange MTA' => 0x87, 'Microsoft Exchange IMC' => 0x6A, 'Network Monitor Agent' => 0xBE, 'Network Monitor Application' => 0xBF, 'Domain Master Browser' => 0x1B, 'Domain Controllers' => 0x1C, 'Master Browser' => 0x1D, 'Browser Service Elections' => 0x1E, 'IIS' => 0x1C, 'Lotus Notes Server Service' => [0x2B], 'Lotus Notes' => [0x2F], 'Lotus Notes' => [0x33], 'DCA IrmaLan Gateway Server Service' => [0x20] ); my %sv_flags = ( WORKSTATION => 0x00000001, SERVER => 0x00000002, SQLSERVER => 0x00000004, DOMAIN_CTRL => 0x00000008, DOMAIN_BAKCTRL => 0x00000010, TIME_SOURCE => 0x00000020, AFP => 0x00000040, NOVELL => 0x00000080, DOMAIN_MEMBER => 0x00000100, PRINTQ_SERVER => 0x00000200, DIALIN_SERVER => 0x00000400, SERVER_UNIX => 0x00000800, NT => 0x00001000, WFW => 0x00002000, SERVER_MFPN => 0x00004000, SERVER_NT => 0x00008000, POTENTIAL_BROWSER=> 0x00010000, BACKUP_BROWSER => 0x00020000, MASTER_BROWSER => 0x00040000, DOMAIN_MASTER => 0x00080000, SERVER_OSF => 0x00100000, SERVER_VMS => 0x00200000, WIN95_PLUS => 0x00400000, ALTERNATE_XPORT => 0x20000000, LOCAL_LIST_ONLY => 0x40000000, DOMAIN_ENUM => 0x80000000 ); # NetBIOS flags my %nb_flags = ( NB_GROUP => 0x80, NB_PERM => 0x02, NB_ACTIVE => 0x04, NB_CONFL => 0x08, NB_DEREG => 0x10, 'Broadcast node type' => 0x00, # NB_BFLAG 'Point-to-point node type' => 0x20, # NB_PFLAG 'Mixed bcast & p-p node type' => 0x40, # NB_MFLAG 'Microsoft hybrid node type' => 0x60, # NB_HFLAG 'Mask applied to outgoing NetBIOS flags' => 0xE0 # NB_FLGMSK ); ############################################################################ sub usage #29.08.99 0:34 ############################################################################ { print <; # skip VERSION while ( $line = ) { chomp $line; $line =~ s/"//g; # strip '"' my ( $name, $ttl, @ip ) = split(/ /,$line); my $wins_flag; ( $name, $wins_flag )= split(/#/,$name); my $nb_flag = pop @ip; undef $nb_flag if ( $nb_flag =~/S$/ ); # SELF name encoding # probably should be ignored... $nb_flag =~ s/R$//; # strip R, # REGISTER name encoding $nb_flag = hex $nb_flag; $ip = join (',', @ip ); $dat{$ip}{ttl} = $ttl; if ( $wins_flag == 0 ) { # Workstation Service only $dat{$ip}{name} .= ',' if ( defined $dat{$ip}{name} ); $dat{$ip}{name} .= $name; } $dat{$ip}{nb_flag} = $nb_flag; $dat{$ip}{wins_flag} .= ',' if ( defined $dat{$ip}{wins_flag} ); $dat{$ip}{wins_flag} .= $wins_flag; } open BROWSE, $path.'browse.dat' or die $!; while ( $line = ) { chomp $line; $line =~ s/ +/ /g; # remove extra spaces $line =~ s/" /",/g; # replace '" ' with '",' $line =~ s/ "/,"/g; # replace ' "' with ',"' $line =~ s/"//g; # strip '"' my ($name, $sv_flag, $comment, $wgrp) = split(/,/,$line); $sv_flag = hex $sv_flag; while ( ($ip, $href) = each (%dat) ) { if ( $href->{name} eq $name ) { $dat{$ip}{sv_flag} = $sv_flag; $dat{$ip}{comment} = $comment; $dat{$ip}{wrkgrp} = $wgrp; keys %dat; # reset each iterator; # otherwise, each will _continue_ last; } } } my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst); while ( ($ip, $href) = each (%dat) ) { if ( defined $opt_ip[0] ) { next if ( $opt_ip[0] ne $ip ); } if ( defined $opt_name[0] ) { next if ( $opt_name[0] ne $href->{name} ); } if ( defined $opt_sub[0] ) { next if ( ! ($ip =~ $opt_sub[0]) ); } print "Name: $href->{name} IP: $ip Comment: $href->{comment} "; print "Workgroup: $href->{wrkgrp} "; print "WINS: $href->{wins_flag}\n"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($href->{ttl}); $mon++; $year += 1900; print "TTL: $mday/$mon/$year $hour:$min:$sec ($wday $yday $isdst)\n"; my $sv_flag; while ( ($meaning, $sv_flag) = each(%sv_flags) ) { if( $href->{sv_flag} & $sv_flag ) { print "\t$meaning\n"; } } print "\n\n"; }