sub get_novell_table { print "Running Z:USERS /A /C... "; open(NL,"Z:NLIST USERS /A /C |") || die "couldn't run nlist"; @nl = ; close(NL); # Output of nlist is now in array @nl, one element per line # Turn into a lookup table of user names keyed by ethernet address foreach (@nl) { # parse each line into name and address if (/(\S+)\s*\[.*\]\[\s*(\S+)\]/) { $name = $1; $adr = $2; # zero extend on left hand to 12 places $adr = "0" x (12-length($adr)).$adr; $adr2name{$adr} = $name; } } print "Found ", 0+keys(%adr2name), " logged in Novell users. \n"; } # Get my own IP address sub my_ip { local($x); $x = `nbtstat -n`; if ($x =~ /\[(\d.*\d)\]/) { return $1; } return ""; } sub nbtstat { local(@x,$x,$ip); $ip = $_[0]; $x = `nbtstat -A $ip`; @x = split(/\n/, $x); return grep(/<03>/,@x); } sub arp { local(@x,$x,$ip); $ip = $_[0]; #print "arp -a $ip \n"; $x = `arp -a $ip`; #print $x; @x = split(/\n/, $x); foreach (@x) { if (/([\dA-Fa-f]+-.*-[\dA-Fa-f]+)/) { $a = $1; $a =~ s/-//g; $a =~ tr/a-z/A-Z/; #print "got $a\n"; return $a; } } return ""; } &get_novell_table(); $my_ip = &my_ip(); $net = $my_ip; $net =~ s/\.\d+$//; open(LOG,">pingem.log") || die "Could not create pingem.log "; select((select(LOG),$| = 1)[0]); $low = 1; $hi = 254; print "Scan from: [ENTER for $low] >"; $low2 = ; $low2 =~ s/[\s\n]*//gi; if ($low2 ne "") { $low = $low2; } print "Scan to: [ENTER for $hi] >"; $hi2 = ; $hi2 =~ s/[\s\n]*//gi; if ($hi2 ne "") { $hi = $hi2; } print "Scanning for active IP addresses from $net.$low to $net.$hi.\n"; printf("%16s %20s %20s\n", "IP Address", "IPX/Ethernet Adr", "Novell Username"); for ($_=$low; $_<=$hi; $_++) { $x = `ping -n 2 -w 10 $net.$_`; $ipa = $net.".".$_; $nvn = ""; $eth = ""; if ($x =~ /reply/i) { # get ethernet address if ($ipa eq $my_ip) { $eth = "This machine"; } else { $eth = &arp($ipa); } # get novell user name associated with this ethernet address $nvn = $adr2name{$eth}; } $s = sprintf("%16s %20s %20s", $ipa, $eth, $nvn); print $s; if ($eth eq "") { print "\r"; } else { print "\n"; } print LOG "$s\n" if ($eth ne ""); } close LOG; print "Log file available in pingem.log.\n"; # @x=(); @x = &nbtstat("$net.$_"); # if (!@x) { # print " no NetBios username"; # } # foreach (@x) { # print "\n $_"; # print LOG " $_\n"; # } # print "\n";