Article 3857 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:3857
Path: feenix.metronet.com!news.ecn.bgu.edu!anaxagoras.ils.nwu.edu!news.acns.nwu.edu!casbah.acns.nwu.edu!navarra
From: navarra@casbah.acns.nwu.edu (John Navarra)
Newsgroups: comp.lang.perl
Subject: con - user-friendly network connection utility, Part 01/01
Date: 30 Jun 1993 03:42:06 GMT
Organization: Northwestern University, Evanston IL
Lines: 1055
Distribution: world
Message-ID: <20r22e$c72@news.acns.nwu.edu>
NNTP-Posting-Host: casbah.acns.nwu.edu


Recently, my con Perl script appeared in comp.sources.unix. I submitted it
last year and since then I made some changes. I am posting the new source
here in comp.lang.perl since I figure anyone interested in this would first
see it here anyway. If there is sufficient interest, I will resubmit it 
to c.s.u.  

I usually don't have time to read this group all the time so if you have
any questions about the utility, you can mail me directly. The README file
describes some of what con does but the man page goes into detail.
Basically, if you are an Internet-junky, con will save you a bit of typing!

Enjoy,
-tms


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  IMPROVEMENTS README README.first aftp con sample_hostsfile
# Wrapped by navarra@casbah.acns.nwu.edu on Tue Jun 29 22:32:16 1993
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'IMPROVEMENTS' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'IMPROVEMENTS'\"
else
echo shar: Extracting \"'IMPROVEMENTS'\" \(573 characters\)
sed "s/^X//" >'IMPROVEMENTS' <<'END_OF_FILE'
XA few changes have been made to con since it was first posted to
Xcomp.sources.unix. Here is a short list of improvements. The details
Xare described in the man page.
X
X*) improved Configuration section.
X
X*) added CHECK_NETRC_ENTRY subroutine to make automatic .netrc entry if
X   an anonymous entry is made in HOSTSFILE but does not exist in .netrc.
X
X*) improved aftp (auto ftp) program so that you can ftp multiple files
X   using shell metacharacters on command line.
X
X*) updated man page/ corrected mistakes.
X
X*) updated code/ fixed mistakes. Got rid of some stupid stuff!
X
END_OF_FILE
if test 573 -ne `wc -c <'IMPROVEMENTS'`; then
    echo shar: \"'IMPROVEMENTS'\" unpacked with wrong size!
fi
# end of 'IMPROVEMENTS'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(2559 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X
XCon is a perl script which facilitates con(tacting) different hosts
Xusing a variety of options. It was written so its users did not have
Xto make a mess of functions, aliases, or other strange contortions
Xso they could get at their favorite computers. Instead, con uses a 
Xfile called .hosts (or whatever you want to call it), and a few 
Xenvironmental variables to determine what exactly you want to do 
Xwith minimal typing. The basic idea is that you have already provided
Xthe information beforehand and are now just using it again. For instance,
Xthe typical entry in .hosts looks like this:
X
X129.105.113.53 <TAB>  casbah.acns.nwu.edu sunny  <TAB> navarra 
X
XThe format is exactly like /etc/hosts except for the possible third
Xfield. 
X
XNow, con makes use of this information in the following way. Say you 
Xwant to rsh to casbah.
Xwith con:
X
X	$ con -r cas
X        $ [alternatively] rsh casbah.acns.nwu.edu -l navarra 
X
X
XNow, say you had a .rhosts entry for yourself on casbah and you wanted 
Xto use rsh to look at a file on a remote machine. With con, this becomes,
X
X	$ con -r cas cat filename
X      	$ [alternatively] rsh casbah.acns.nwu.edu -l navarra cat filename
X
XNot good enough you say! (surely you jest). You tell me your shell has 
Xhostname completion so I can easily expand casbah. Then, con is not saving
Xme all that much typing. Ok, I see your point. Therefore, con also uses
Xthe enviromental variable DEFAULT_OPT=/usr/ucb/rsh (that is what it is
Xrecommended to be anyway). Now, the command to check your file is now
Xdown to this:
X
X	$ con cas cat filename
X
XWhat? Still not good enough! (my you are hard to please! ;-) 
XWell, what if you could make a link to con, (call it say, casbah) and
Xhave con recognize what you want to do. Ok, now the command becomes
X
X	$ casbah cat filename
X
Xor to log in as someone else
X	
X	$ casbah -l jarvis 
X
Xor to finger someone
X
X	$ casbah -F jarvis
X
Xtalk
X	$ casbah -T jarvis
X
Xor mail jarvis some really cool material! ;-)
X
X	$ casbah -m jarvis Interesting Stuff < alt.sex.beastiality
X
X(so jarvis is kinda weird.)
XAnd there are many other cool options which all save time when typing. The
Xcon man page goes into all the excruciating detail. 
X
X	Con is free. However, if you want to send me money -- sure, I'll
Xtake it. I do not have any formal copyright on con -- all that legal stuff 
Xis garbage anyway. I only ask that you leave my name attached to this
Xprogram. If you want to make any modifications, or have any suggestions,
Xcriticisms, ideas, etc, feel free to mail them to me. 
X
XEnjoy,
X
XJohn Navarra
Xnavarra@nwu.edu
X
X 
END_OF_FILE
if test 2559 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'README.first' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README.first'\"
else
echo shar: Extracting \"'README.first'\" \(645 characters\)
sed "s/^X//" >'README.first' <<'END_OF_FILE'
X
XIf you got con off the comp.sources.unix listserv, there seems to be 
Xa problem with it replacing TABS with spaces. TABS are crucial in the
Xcon source code in the GET_COMP subroutine (line 148):
X
X              ($IP, $computer, $username)=split(/        /,$_);
X
XThe IP, domain name, and username fields in HOSTSFILE  *MUST* be separated
Xby TABS. Additionally, in the sample_hostsfile which comes with the
Xdistribution, any SPACES between these fields must be converted to TABS. 
XNote, however, that the domain name and any aliases you want are separated
Xby SPACES. For example:
X
X129.105.113.53 <TAB>  casbah.acns.nwu.edu sunny  <TAB> navarra 
X
X
END_OF_FILE
if test 645 -ne `wc -c <'README.first'`; then
    echo shar: \"'README.first'\" unpacked with wrong size!
fi
# end of 'README.first'
fi
if test -f 'aftp' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'aftp'\"
else
echo shar: Extracting \"'aftp'\" \(1638 characters\)
sed "s/^X//" >'aftp' <<'END_OF_FILE'
X#! /usr/bin/perl 
X
X# aftp -- A simple perl script to automate anonymous ftp to a site to
X#	  get file(s). Aftp comes with the con distribution but may also
X#	  be used separately. For more details using aftp, see the con
X#	  man page.
X# Author: John Navarra (navarra@casbah.acns.nwu.edu)
X
X# set up some variables 
X$MODE=$ENV{'MODE'};
X$FTP='/usr/ucb/ftp';
X$ME=$ENV{'USER'};
X$HOSTNAME=`hostname`;
X
Xsub y_or_n {
X	local($prompt) = @_;
X	print STDOUT $prompt;
X	local($answer)=scalar(<STDIN>);
X	if ( $answer !~ /^n/i )  {
X	}
X	else {
X  	  if ($MODE =~ ascii) { 
X	     $MODE=bin;
X          }
X          else {
X             $MODE=ascii;
X           } 
X	}
X
X}
X# If aftp was not called with an ascii or bin option so we will go thru 
X# some rigamorole to figure out the correct mode.  
Xif ($ARGV[0] !~ /^-/) {
X   &y_or_n("Transfer using $MODE mode? [yes] ");
X}
X
Xwhile ($ARGV[0] =~ /^-/) {
X   $_ = shift;
X   if (/^-ascii|^-a/) {
X      $MODE=ascii;
X   }
X   elsif (/^-bin|^-b/) {
X      $MODE=bin;
X   }
X   else {
X      print "aftp: not an option! Use -a[scii] or -b[in] \n";
X      exit(0);
X   }
X}
X$computer=shift;
X#print "Ftping to $computer using $MODE mode ... \n ";
X
X# Let's do some ftp shall we?
Xopen(FTP, "| $FTP -n $computer"); 
Xprintf(FTP "user anonymous $ME@$HOSTNAME \n");
Xprintf(FTP "$MODE \n" );
Xforeach $path (@ARGV) {
X   ($basename = $path) =~ s!.*/!!;
X   ($dirpath = $path) =~ s!/[^/]*$!!;
X   printf(FTP "cd $dirpath \n");
X   if ($basename =~ /\*/ ) {
X	printf(FTP "prompt \n");
X	printf(FTP "mget $basename \n");
X   } else { 
X	printf(FTP "get $basename \n");
X	printf(FTP "\!echo got $basename \n");
X   }
X}
Xclose (FTP);
X
Xprint "Got'em! \n ";
X  
END_OF_FILE
if test 1638 -ne `wc -c <'aftp'`; then
    echo shar: \"'aftp'\" unpacked with wrong size!
fi
# end of 'aftp'
fi
if test -f 'con' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'con'\"
else
echo shar: Extracting \"'con'\" \(24236 characters\)
sed "s/^X//" >'con' <<'END_OF_FILE'
X#! /usr/bin/perl
X'di';
X'ig00';
X#
X# $Header$
X#
X# $Log$
X# Name: Con     a program to facilitate contacting other machines in a number
X# Version: 1.1  of different ways.  
X# Author:       John Navarra (navarra@nwu.edu)
X
X#=====================CON CONFIGURATION SECTION=============================#
X# Special variables
X
X# 	The user may also want to consider setting $HOSTSFILE to his
X# hostname_completion_file (bash) or to whatever variable or path is
X# appropriate depending on your shell.
X$HOSTSFILE=$ENV{'HOSTSFILE'};
X
X# If your hostname command doesn't return the fully qualified domain name,
X# just insert your hostname here. Be sure to put the name in quotes!
X$HOSTNAME=`hostname`;
X
X# this should be set to your .netrc file in your home directory.
X$NETRCFILE=$ENV{'NETRCFILE'};
X
X# we use rsh so you can specify a command on the command-line.
X# I use the enviromental variable DEFAULT_OPT so more than one person
X# can run the same con with different default options set 
X$DEFAULT_OPT=$ENV{'DEFAULT_OPT'};
X$ME=$ENV{'USER'};
X
X# if $CHECK_HOST is set to 'yes' then failed matches of possible hostnames
X# in $HOSTSFILE will result in a query asking the user if that match is
X# desired as an addition to the hosts file. Otherwise, con will return
X# with the error message "Couldn't find pattern in hosts file."
X$CHECK_HOST=$ENV{'CHECK_HOST'};
X
X# The enviromental variable MAILER is used to determine which mail 
X# program to use. Con barfs with /bin/mail (which no one should be
X# using anyway)  
X$MAILER=$ENV{'MAILER'};
X
X# regular commands and paths. Change these if not correct. 
X$AFTP='/home/cartan/navarra/perl/aftp';
X$FINGER='/usr/ucb/finger';
X$FTP='/usr/ucb/ftp';
X$PING='/usr/etc/ping';
X$RLOGIN='/usr/ucb/rlogin';
X$RSH='/usr/ucb/rsh';
X$TALK='/usr/ucb/talk';
X$OTALK='/usr/ucb/otalk';
X$TELNET='/usr/ucb/telnet';
X$TRACEROUTE='/usr/etc/traceroute';
X
X#============================================================================#
X
X# Usage message subroutine.
Xsub USAGE_MESG {
X	print STDERR "Usage: con [-options] machine \n";
X}
X# Yes or no subroutine.
Xsub y_or_n {
X        local($prompt) = @_;
X        print STDOUT $prompt;
X        local($answer)=scalar(<STDIN>);
X        exit (0) if $answer =~ /^n/i;
X}
X# Subroutine to collect entry for hostsfile.
Xsub FORM_ENTRY {
X        foreach $arg (@_) {;
X        print "Enter info or hit return to accept [$arg] "; 
X        chop($response=scalar(<STDIN>));
X        $response=$response || $arg;
X        }
X        $response;
X} 
X# Subroutine to make entry in hostsfile
Xsub MAKE_ENTRY {
Xopen(HOSTSFILE, ">>$HOSTSFILE") || die "can't open $HOSTSFILE: $! \n";
Xif ($username) {
Xprintf(HOSTSFILE "$ipaddress	$machine	$username\n");
X} 
Xelse {
Xprintf(HOSTSFILE "$ipaddress	$machine\n");
X}
Xclose(HOSTSFILE);
X#should we exit after updating hostfile or continue? You can always !!
Xexit(0);
X}
X
X# This is only for making standard .netrc entries of machine and login
X# names and passwords. Calling this subroutine assumes you have an
X# anonymous entry in your hostsfile.
Xsub CHECK_NETRC_ENTRY {
X        open(NETRCFILE, $NETRCFILE ) || die "Can't open $NETRCFILE: $! \n";
X        while (<NETRCFILE>) {
X           if ( /$domain/) {
X              return(1);
X           }
X        }
X        print "Didn't find $domain in $NETRCFILE.\n";
X        print "Make entry? [yes]";
X        if ( <STDIN> !~ /^n/i ) {
X           open(NETRCFILE,">>$NETRCFILE") || die "Can't open $NETRCFILE: $!\n";
X           printf(NETRCFILE "\nmachine $domain\n");
X           printf(NETRCFILE "login anonymous\n");
X           printf(NETRCFILE "password $ME@$HOSTNAME\n");
X           close(NETRCFILE);
X        }
X}
X
X# Subroutine to get ip address of a machine.
Xsub GET_IP {
X	($domain, $aliases)=split(/ /,$machine);
X 	$addrs = (gethostbyname($domain))[4];
X        ($a, $b, $c, $d)=unpack('C4', $addrs);
X        $IP="$a.$b.$c.$d";	
X
X}
X# Subroutine to get proper username when contacting machine.
Xsub GET_PROPER_NAME {
X	$id=shift(@ARGV);
X        # some options like talk may want a tty as last arg.
X	#check if id is a tty. If so, unshift to get back @ARGV.
X	if ( $id =~ /tty\w\d/) {
X	   unshift(@ARGV, $id);
X	   $propername=$username || $ME;
X	}
X	else {
X	   $propername=$id || $username || $ME;
X	} 
X}
X
X# Subroutine to get correct info from HOSTSFILE. 
Xsub GET_COMP {
X    open(HOSTSFILE, $HOSTSFILE ) || die "Can't open $HOSTSFILE: $! \n";
X       # For rsh-like ability. You can ln -s con host and then just
X       # type host -option etc to run con. 
X       if ( $0 =~ /con/) {
X            $pattern = shift(@ARGV);
X       }
X       else {
X  	    ($pattern=$0) =~ s!.*/!!;
X       }		
X       while (<HOSTSFILE>) {
X          if (/$pattern/) {
X             ($IP, $computer, $username)=split(/	/,$_);
X	     #ok, this is a big pain but it is neccessary to make sure
X	     #right thing is chopped. 	
X	     if ($username) {
X		chop $username;	
X	     } else {
X	        chop $computer;
X	     }
X	     #want to use FQDN so ftp can make use of .netrc file.
X	     ($domain, $aliases)=split(/ /,$computer);
X	     #last field in hosts tends to acquire extra characters.
X	     # I will have to probably chop them all but do that later.
X	     #chop $username;	
X          }
X       }
X       if (!$computer && $CHECK_HOST eq 'yes') {
X	  &y_or_n("No pattern in hostfile. Do you want to make an entry [yes]");
X	  print "ok, you will be prompted separately for a domain name \n";
X	  print "with aliases, an IP address, and a possible username. \n";
X	  $machine=&FORM_ENTRY($pattern);
X	  &GET_IP;
X	  $ipaddress=&FORM_ENTRY($IP);
X	  $username=&FORM_ENTRY("");
X          &y_or_n("Accept: $ipaddress    $machine        $username [yes]");
X	  &MAKE_ENTRY;
X       }
X       if (!$computer) {
X	  print STDERR "Couldn't find $pattern in $HOSTSFILE \n";
X	  exit(0); 
X       }
X}
X
X	
X#======================== Begin main program ===============================#
X
X#Do Null switch checking first. If this succedes, use DEFAULT OPTION. 
Xif ($ARGV[0] !~ /^-/) { 
X   &GET_COMP;
X   if ( $username =~ anonymous ) {	
X      if (@ARGV) {
X	 #aftp is automatically called with no option. Aftp will take care
X         #of finding the right mode for file transfer. 
X	 #print "$AFTP to $domain getting file @ARGV \n";
X         system("$AFTP $domain @ARGV");  
X      } else {
X	# Does .netrc entry exist? Does .netrc exist?
X	&CHECK_NETRC_ENTRY;
X        #print "$FTP to $domain \n";
X        system("$FTP $domain");
X      }
X   } 
X   elsif ( $DEFAULT_OPT eq $RSH ) {
X      #the line below assures a propername existing. However, if you do
X      #not want to rsh with $username or $ME, rsh will still accept the
X      #line 'rsh host -l username1 -l username2 [commands]'
X      $propername= $username || $ME;
X      #print "Null switch: $DEFAULT_OPT to $IP with $propername @ARGV .\n";
X      system("$DEFAULT_OPT $domain -l $propername @ARGV");
X      exit(0);
X   }
X   else {
X    # telnet is the next likely default selection -- use that syntax. 
X    system("$DEFAULT_OPT $IP @ARGV");
X   }
X}
X
X# Parse other options.
X
Xwhile ($ARGV[0] =~ /^-/) {
X    $_ = shift;
X    if (/^-l/) {
X	&GET_COMP;
X		print "Internet Address: $IP \n";
X		print "Computer name: $computer \n";
X		print "Domain name: $domain     Aliases: $aliases \n";
X		$username='<none>' if (!$username);
X 		print "Common username (or friend): $username   \n";  
X	exit(0);
X    }
X    elsif (/^-w/) {
X        open(HOSTSFILE, ">>$HOSTSFILE") || die "can't open $HOSTSFILE: $! \n";
X        printf(HOSTSFILE "@ARGV\n");
X        close(HOSTSFILE);
X        print "appended @ARGV to $HOSTSFILE \n";
X	exit(0);
X    }
X    elsif (/^-h/) { 
X	print STDOUT <<"END_OF_HELP";
X
X		Con help screen (anything in [] are optional)
X
XOption   usage explanation                      usage
X------------------------------------------------------------------------------
X""|-r    rsh host [username] [commands]         con -r host [username] [cmds]
X-t       telnet host [port]                     con -t host [port]
X-f       ftp host [filename]                    con -f host [/pathtofile]
X-F       finger [-fopt] username@host           con -F host [user] [fopt]
X-h       print brief help screen                con -h
X-l       list host info                         con -l host
X-m       Mail|elm [-s subject] username@host    con -m host [user] ['Subject']
X-p       ping [-option] host [other]            con -p host [-opt] [other]
X-R       traceroute [[-opt] other] host         con -R host [[-opt other]
X-T|To    [o]talk username@host [tty]            con -T[o] host [user] [tty]
X         Note: no packetsize opt available.
X-w       direct write to HOSTFILE               con -w 'IP<TAB>addr<TAB>name'
X
XEND_OF_HELP
X
X	#print STDOUT "\f";
X    }	
X    elsif (/^-p/) {
X	&GET_COMP;
X        # make con [-p] host [-option]
X          if (@ARGV[0] =~ /^-/) {
X             $add_opts=shift(@ARGV);
X             #print "loop1: $PING $add_opts $IP @ARGV \n";
X             system("$PING $add_opts $IP @ARGV");
X          }
X          else {
X             #print "loop 2: $PING $IP @ARGV \n";
X             system("$PING $IP @ARGV");
X          }
X    }
X    elsif (/^-R/) {
X	#No packet capibility. Too hard to parse all the options to traceroute
X	&GET_COMP;
X	system("$TRACEROUTE @ARGV $IP");
X	exit(0);
X    }
X    elsif (/^-r/) {
X	&GET_COMP;
X	#propername will always exist. 
X	$propername= $username || $ME;
X	#print "$RSH $IP -l $propername @ARGV \n"; 
X	system("$RSH $IP -l $propername @ARGV");	
X	exit(0);
X    }
X    elsif (/^-f|^-fa|^-fb/) {
X	if (/^-fa/) {
X	   &GET_COMP;
X 	   #print "aftp -a to $domain for file(s) @ARGV \n";
X	   system("$AFTP -ascii $domain @ARGV");
X           }
X        elsif (/^-fb/) {	
X	   &GET_COMP;
X	   #print "aftp -b to $domain for file(s) @ARGV \n";
X	   system("$AFTP -bin $domain @ARGV");
X	   }
X	else {
X	   &GET_COMP;
X	   if (@ARGV) {
X	      #again, aftp will find the right mode. 
X	      #print "aftp to $domain for file(s) @ARGV \n";
X              system("$AFTP $domain @ARGV");
X           }
X	   else {
X              # Note that we don't check .netrc entry here. No reason to.
X	      #print "$FTP to $domain \n";
X	      system("$FTP $domain");
X	   }
X	}
X	exit(0);
X    }
X    elsif (/^-t/) {
X	&GET_COMP;
X 	if (@ARGV) {
X	#print "$TELNET to $IP on port # @ARGV \n";
X	system("$TELNET $IP @ARGV");	
X	}
X	#this will match any number (I think). If you have a username
X	#consisting of entirely numbers, con will think it is a valid
X 	#port # with the -t option. I don't think this is usually the
X	#case so for now, a legit port number can be in the username
X	#field for use with this option.
X        elsif ($username =~ /^(\d+\.?\d*)$/) {
X	#print "$TELNET to $IP on port # $username \n";
X	system("$TELNET $IP $username");
X	} else {
X	#print "$TELNET to $IP \n";
X	system("$TELNET $IP");
X	}
X	exit(0);	
X    }
X    elsif (/^-m/) {
X	&GET_COMP;
X 	&GET_PROPER_NAME;	
X	print "$MAILER -s \"@ARGV\" $propername@$domain \n";
X	#exec this in a subshell so '< filename' can be used on
X	#the commmand line
X	system("($MAILER -s \"@ARGV\" $propername@$domain)");
X	exit(0);
X   }
X    elsif (/^-F/) {
X	#make finger [-opts] username@host 
X	&GET_COMP;
X          if (@ARGV[0] =~ /^-/) {
X		$finger_opt=shift(@ARGV);
X		&GET_PROPER_NAME;
X 		#print "loop1: $FINGER $finger_opt $propername@$IP \n";
X 		system("$FINGER $finger_opt $propername@$IP");
X		exit(0);
X	  }
X	  else {
X		&GET_PROPER_NAME;
X		#print "loop2: $FINGER @ARGV $propername@$IP \n";
X		system("$FINGER @ARGV $propername@$IP");
X		exit(0);
X	  }
X    }
X    elsif (/^-T|^-To/) {
X	#make talk username@host [tty]
X	   if (/^-To/) {
X		&GET_COMP;
X		&GET_PROPER_NAME;
X		#print "loop1: $OTALK $propername@$IP @ARGV\n";
X		system("$OTALK $propername@$IP");
X		exit(0);
X	   }
X	   else {
X		&GET_COMP;
X		&GET_PROPER_NAME;
X		#print "loop2: $TALK $propername@$IP @ARGV \n";	
X		system("$TALK $propername@$IP");
X		exit(0);
X	   }
X    } else  {
X	print STDERR "Unrecognized switch: $_ \n";
X	&USAGE_MESG;
X    } 
X}
X
X
X
X###############################################################
X
X    # These next few lines are legal in both Perl and nroff.
X
X.00;                       # finish .ig
X 
X'di           \" finish diversion--previous line must be blank
X.nr nl 0-1    \" fake up transition to first page again
X.nr % 0         \" start at page 1
X'; __END__ ##### From here on it's a standard manual page #####
X
X.TH CON 1 "May 2, 1992"
X.AT 3
X.SH NAME
Xcon \- A program to facilitate contacting a host in a variety of ways.
X.SH SYNOPSIS
X.B con  
X[
X.B -''fFhlmprRtTw
X] [
X.B hostname
X] [
X.B other
X]
X.SH DESCRIPTION
X.I Con
Xis a perl script that facilitates the various ways of connecting to a
Xmachine, remote or local, by minimizing the repetitive (and unneeded) 
Xtyping one has to do to uniquely identify a host, a login name, and an
Xoption (telnet, rlogin, etc). 
X.I Con
Xis used in conjunction with a few environmental variables and a hosts
Xfile whose syntax is similiar to /etc/hosts. 
X
XThe primary environmental variable used is 
X.I HOSTSFILE
Xwhich specifies the path to a file which contains the following information:
X
XIP ADDRESS      domain name aliases       possible username
X129.105.113.52  casbah.acns.nwu.edu cas   navarra
X
XEach field must be separated by a <TAB> and each domain name alias must 
Xbe separated by a <SPACE>. The HOSTSFILE need not reside in your home
Xdirectory (although that is probably wise). For bash and/or zsh compatibility
Xyou can set HOSTSFILE to whatever file you use for hostname completion.
X 
X.I Con
Xuses the HOSTSFILE as a reference to find the correct computer (and possible
Xusername) to use when called with one of many options. Thus, the user need 
Xnot type the full domain name address to connect, only enough to uniquely
Xidentify the requested computer. For possible hosts casbah.acns.nwu.edu and
Xcannibal.acns.nwu.edu, the user could identify casbah with the call 'con
Xcas' but not with the call 'con ca'.
X
X.SH USAGE
X
X.I Con
Xhas many different options. Some of those are used far more than others.
XFor that reason, 
X.I con 
Xuses the variable 
X.I DEFAULT_OPT
Xas a null option. The configuration section sets up DEFAULT_OPT as an
Xenviromental variable. This need not be the case if all who use con agree
Xon a DEFAULT_OPT. It is recommended that
X.I rsh
Xbe used for reasons which will become apparent later in the document. For
Xthe sake of explaining the use of 
X.I con,
XI will assume this is the case. 
X
X.SH OPTIONS
X
X""|-r) rsh host [username] [commands] or
X       ftp [or auto ftp] host [filename]
X
Xpart 1 [rsh]: 
X       The most common use for 
X.I con  
Xwill be logging into a remote computer. The null option or -r option
Xuses the same syntax as 
X.I rsh. 
XThe proper username to use with this option is determined as follows:
XA username specified on the command line is used before any username in
XHOSTSFILE. To specify a username on the command line, use the same
Xsyntax as
X.I rsh:
X
X      %example: con cas -l username [commands]
X
XIf no username is specified on the commmand line, the username in the
Xthird field of HOSTSFILE is used. If no username exists in HOSTSFILE
Xthen the username on the local machine ($USER) is used. Note: because
Xthis option always defaults to $USER, there is no reason to put your
Xusername on local machine as the third field in HOSTSFILE.
X
XLike rsh, 
Xif the name of the file from which 
X.I con 
Xwas executed is anything other
Xthan ``con'', that name will be used as its
X.I hostname
Xargument. Thus, if a symbolic link is made to con with a unique hostname
Xto search for in HOSTSFILE, that name will be used (along with any con
Xoption) to connect to a host. This feature is particularly useful to
Xcut down on needless typing. All command lines will now be of the form:
X
X     hostname -con_opt [-other_opt]  [username] [other]
X     %example: casbah -r -l bill cat file 
X               #rsh casbah.acns.nwu.edu -l bill cat file 
X
Xpart 2 [ftp]:
X     If the username field of HOSTSFILE contains the string 'anonymous',
X.I con
Xwill perform an ftp to the host.  
X.I Con
Xwill work in conjunction with the 
X.I .netrc
Xfile to automatically log you into the remote computer. If the machine
Xname whose entry contains the string 'anonymous' does not have a 
X.I .netrc
Xentry, 
X.I con
Xwill ask you if you want to make one automatically. A standard machine
Xname, login name, and password entry will be appended to your 
X.I .netrc
Xfile where login name is anonymous and the password is your username
Xat your local hostname.
X
XIf a path-to-filename is given as the last argument, 
X.I con
Xwill use the 
X.I aftp
X[auto ftp] program which comes with the distribution. This program will 
XNOT use your 
X.I .netrc 
Xfile but will log you in to the remote host with 'local_username@local_host'.
XThe filename MUST be the full path name to the file you want to get.
X(unless you are getting different files in the same directory -- see example
Xbelow.)
X.I Aftp   
Xuses the enviromental variable MODE (bin or ascii) to determine which
Xmode you want to transfer your file with. However, just as a precaution,
X.I aftp
Xasks for confirmation before it gets the file. The recieved file is left
Xin whatever directory 
X.I con
Xwas invoked from.
X.I Aftp
Xcan also get multiples files from one directory, just include a ``*''
Xin the full pathname argument. 
X
X      %example: con prep
X                #username=anonymous ==> ftp prep.ai.mit.edu
X      %example: con prep /pub/gnu/filename.tar.Z
X                #auto ftp to prep for filename.tar.Z
X      %example: con uu /published/unix-world/*
X                #auto ftp to ftp.uu.net to do an mget on all
X                #files in directory /published/unix-world.
X      %example: con prep /pub/tools/foo ./bar
X                #auto ftp to prep for files foo and bar in
X                #directory /pub/tools. Note the "./" before
X                #the "bar". This keeps the current directory
X                #without having to specify the full path.
X
XThe 
X.I aftp
Xis fairly robust but you can use your own version if you want. It may,
Xof course not be completely compatible. I am looking for more ways to
Ximprove it.
X
X-t) telnet host [port]
X
X    A port number may be specified on the command line or as a username
Xin HOSTSFILE. As usual, if a port number is specified on the command line,
Xit will take precedence over the username field. 
X
X      %example: con -t phoenix 25
X                #telnet to mail port on phoenix.whatever 
X
XNote: if you use telnet as a default option, the port number ability in
XHOSTSFILE is lost. The number check is only made when using this option.
X
X-f|-fa|-fb) ftp [or auto ftp] host [filename]
X
X    This option works in the same manner described above to ftp to a
Xhost. The difference is that the user may specify directly what mode
Xhe wants the files to be transferred in (thus bypassing confirmation
Xby
X.I aftp
X)
XAlso, this option, (-f), is used for hosts which are not strictly going 
Xto be contacted for anonymous ftp (no 'anonymous' string in HOSTSFILE). 
X
X-F) finger [-opts] username@host
X
X     This option is used to finger a username. Any valid finger option can
Xbe used but must be the last argument. The username precedence is the same 
Xas above.
X
X      %example: con -F cas nut-boy [-l]
X                #finger [-l] nut-boy@casbah.acns.nwu.edu
X
X      %example: con -F prin -s
X                #finger -s (name in 3rd field)@princeton.edu
X
X      %example: con -F cas " "
X                #finger everyone at casbah. Note the default 
X                #is always your username so instead, we pass
X                #a " " and this is a good enough hack.
X 
X
X-h) print out brief help screen
X
X    This option displays a half-page help screen which shows how the
Xvarious options are used. 
X
X-l) list host
X
X    This option is used to check an entry in HOSTSFILE. If a pattern is
Xfound, the relevant information on that host is displayed:
X
X     %example: con -l casbah
X               Internet Address: 129.105.113.52
X               Domain name (aliases): casbah.acns.nwu.edu
X               Common username (or friend): <none>
X
X
X-m) Mail or elm [-s "Subject"] username@host [ < filename ]
X
X     This option is used to send mail. It uses the enviromental variable
X.I MAILER
Xto determine which mail program to use. It is recommended that either 
Xelm or Mail are used (no other mailers have been tested so far). Again,
Xas in all other options, this option determines which username to use
Xbased on the order of precedence described above. However, if the user 
Xwants to specify a Suject on the command line, he MUST specify a username.
XOtherwise, the info passed to the mailer can become botched. 
X
X      %example: con -m cas    #MAILER=elm
X                #elm -s "" navarra@casbah.acns.nwu.edu
X                #sends a null subject line and puts user in 
X                #send only mode.
X
X      %example: con -m cas bill this is a test
X                #elm -s "this is a test" bill@casbah
X                #the username bill must be included.
X
X      %example: con -m cas < filename
X                #elm -s "" navarra@casbah < filename 
X
X      %example: con -m cas fred Schedule < Schedule
X                #elm -s "Schedule" fred@casbah < Schedule
X
XIn the last two examples, a file was transmitted. For this operation,
X.I con
Xcreates a subshell and the contents of filename are sent to it to be
Xprocessed by the mailer. 
X
X-p) ping [-opts] host [other]
X
X    This option is used to do a ping on a host. All ping options should
Xbe available.
X
X      %example: con -p cas -v
X                #ping -v casbah.acns.nwu.edu
X
X      %example: con -p cas -s 64 2
X                #ping -s casbah.acns.nwu.edu 64 2
X
X-R) traceroute [opt [other]] host
X
X    This option is used to do a traceroute to a host. Because of the
Xnumerous options to traceroute, the packetsize option is not available
Xdue to parsing problems. All other options are available.
X
X      %example: con -R sage -n
X                #traceroute -n sage.cc.purdue.edu
X
X      %example: con -R sage -nm 5
X                #traceroute -nm 5 sage.cc.purdue.edu
X
X-T|To) [o]talk username@host [tty]
X
X     This option is used to talk to username. Because some vendors are
Xstill using the braindead otalk (now who could that be?), a -To option
Xis available. The username precedence is the same as above. 
X
X      %example: con -T cas jarvis ttyp1
X                #talk jarvis@casbah.acns.nwu.edu ttyp1
X   
X      %example: con -To thor  
X                #username=dick ==> otalk dick@thor 
X
X
X-w) direct write to HOSTSFILE 
X
X    This option is used to make an entry in HOSTSFILE. It is assumed that
Xthe user knows the relavent information neccesary to make a proper entry
X(IP#   domain alias   username). The entry must be enclosed in quotes
Xwith the proper TABS between the fields. A TAB can be entered on the
Xcommand line by typing C-V TAB (control-v TAB). The entry is appended to
Xthe end of HOSTSFILE.
X
X      %example: con -w "129.10.11.3<TAB>io.nwu.edu<TAB>biff"
X        
X.I Con
Xalso provides a more user-friendly way to make entries in HOSTSFILE. 
XIf the environmental variable
X.I CHECK_HOST 
Xis set to ``yes'', then for any hostname pattern entered on the command
Xline not found in HOSTSFILE, the user will be prompted if he wants to 
Xmake an entry. The process is demonstrated as follows: 
X
X[casbah:112] ~ -> con cas
X.PD 0
X.TP
XNo pattern in hostfile. Do you want to make an entry [yes]
X.TP
Xok, your will be prompted separately for a domain name
X.TP
Xwith aliases, an IP address, and a possible username.
X.TP
XEnter info or hit return to accept [cas] casbah.acns.nwu.edu
X.TP
XEnter info or hit return to accept [129.105.113.52]
X.TP
XEnter info or hit return to accept [] fred
X.TP
XAccept: 129.105.113.52    casbah.acns.nwu.edu	fred [yes]
X.br
X
XNote that the IP address is resolved if given a legitimate domain name.
XIn that way, the user just needs to hit RETURN to accept the address
Xand 
X.I con
Xwill make sure it is written correctly to HOSTSFILE. Note also the 
Xthe default username is nothing (fred was used in the example).
X
X
X
X.SH ENVIRONMENTAL VARIABLES
X.PD 0
X.B HOSTSFILE    
X.TP
X.B DEFAULT_OPT  
X.TP
X.B CHECK_HOST  
X.TP
X.B MAILER
X.TP
X.B MODE
X.br
X
X.SH FILES
X.PD 0
X.B $HOME/$HOSTSFILE
X.TP
X.B ./aftp (auto ftp program)
X.br
X
X.SH AUTHOR
X.PD 0
X.B John Navarra (navarra@nwu.edu)
X.TP
X.B Academic Computing and Networking Services
X.TP
X.B Northwestern University 
X.br
X
X.SH BUGS
XThere are probably a few bugs here and there. I have only tested
X.I con
Xon a SunOS and  Mach machines. I am interested in hearing about any
Xbugs and suggestions for improvement. 
X 
END_OF_FILE
if test 24236 -ne `wc -c <'con'`; then
    echo shar: \"'con'\" unpacked with wrong size!
fi
# end of 'con'
fi
if test -f 'sample_hostsfile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'sample_hostsfile'\"
else
echo shar: Extracting \"'sample_hostsfile'\" \(728 characters\)
sed "s/^X//" >'sample_hostsfile' <<'END_OF_FILE'
X# Local hosts
X129.105.113.52	casbah.acns.nwu.edu sun
X129.105.113.32	emma.acns.nwu.edu
X129.105.100.1	aristotle.ils.nwu.edu	blah
X129.105.5.103	delta.eecs.nwu.edu	bill
X129.105.5.15	avalon.eecs.nwu.edu	matt
X129.105.113.31	nestor.acns.nwu.edu nestor
X129.105.113.40	lenny.acns.nwu.edu	navarra
X129.105.113.42	speedy.acns.nwu.edu	navarra
X# Friendly hosts
X128.111.24.70	engrhub.ucsb.edu	harley
X128.210.24.1 	sage.cc.purdue.edu pucc pucc	varney
X128.52.46.26	wombat.gnu.ai.mit.edu gnu	mage
X132.206.2.3	quiche.cs.mcgill.ca	archie
X128.167.254.179	archie.sura.net	archie
X147.225.1.31	archie.ans.net	archie
X# anonymous ftp sites
X137.39.1.9	ftp.uu.net	anonymous
X18.71.0.38	prep.ai.mit.edu	anonymous
X128.252.135.4	wuarchive.wustl.edu	anonymous 
END_OF_FILE
if test 728 -ne `wc -c <'sample_hostsfile'`; then
    echo shar: \"'sample_hostsfile'\" unpacked with wrong size!
fi
# end of 'sample_hostsfile'
fi
echo shar: End of shell archive.
exit 0
-- 
You can get further with a kind word | You can get further with a kind word
and a gun than a kind word alone.    | and a phaser than a kind word and a gun.
          --al capone                |           -- John Navarra
=======From the Lab of the MaD ScIenTIst....navarra@casbah.acns.nwu.edu========