#!/usr/bin/perl

########################################################################
#
# pmfree Ver 2.1 beta2
#
# Portmaster   : ComOS 3.3.1
#
# Description:
# 	This utility will reset all telnet connections to a portmaster.
# 	Occasionally, one of our portmasters will get a bunch of telnet
# 	sessions hung open to the portmaster making it impossible to open
# 	any other telnet sessions to the same machine. This tool fixes the
# 	problems.
# 
# 	usage: pmfree [<portmaster> [<password>]]
# 
#       If no host is specified, then @All hosts are reset
#
#########

require 'pm.pl';

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

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

	@List = &portmaster::Command("show netc");

	foreach (@List) {
	  next unless (/(^\d+).*(\.23)\s+/);
	  $Conn = $1; 
	  &portmaster::Command("reset n$Conn");
	}

	close(portmaster::DS);
}
