#!/usr/bin/perl

########################################################################
#
# pmwho Ver 2.1 beta2
#
# Portmaster   : ComOS 3.3.1
#
# Usage: pmwho [<host> [<password>]]\n";
#
# if no host is specified then @All hosts are checked
#
#######################################################################
require 'pm.pl';

$| = 1;

@Hosts = $ARGV[0] || @All;
$Pass = $ARGV[1] || $Password;

foreach $Host (@All) {
	portmaster::Connect("$Host", $Pass);

	my($Host_id) = $Host;
	$Host_id =~ s/\..*$//; # keep just first part of host name

	# get global vals
	&portmaster::SysGlobal;

	# pm2er's have 31 ports :-(
	$MaxCnt = $GlobalValue{NUMPORTS};

	CNT_LOOP:
	for ($Cnt = 0; $Cnt <= $MaxCnt; $Cnt++) {
		&portmaster::Who("$Cnt");
		if ( $PortValue{$Cnt,PORT} eq "P0" ) {
			# skip Printer port
			next CNT_LOOP;
		}

		if ( $PortValue{$Cnt,PORT} eq "W1" ) {
			# skip WAN port
			next CNT_LOOP;
		}
		printf "%.5s-%3s %10s %15s %13s %15s %4d\n", 
                    $Host_id,
		    $PortValue{$Cnt, PORT}, $PortValue{$Cnt, USERNAME}, 
		    $PortValue{$Cnt, FRAMED_ADDR}, 
		    $PortValue{$Cnt, PORT_TYPE}, $PortValue{$Cnt, STATUS},
		    $PortValue{$Cnt, IDLETIME};
	}

	close(portmaster::DS);
}
