Newsgroups: comp.sources.unix From: navarra@casbah.acns.nwu.edu (John Navarra) Subject: v26i276: con - user-friendly network connection utility, Part01/01 Sender: unix-sources-moderator@gw.home.vix.com Approved: vixie@gw.home.vix.com Submitted-By: navarra@casbah.acns.nwu.edu (John Navarra) Posting-Number: Volume 26, Issue 276 Archive-Name: con/part01 Con is a perl script which facilitates con(tacting) different hosts using a variety of options. It was written so its users did not have to make a mess of functions, aliases, or other strange contortions so they could get at their favorite computers. Instead, con uses a file called .hosts (or whatever you want to call it), and a few environmental variables to determine what exactly you want to do with minimal typing. The basic idea is that you have already provided the information beforehand and are now just using it again. For instance, the typical entry in .hosts looks like this: 129.105.113.53 casbah.acns.nwu.edu sunny navarra The format is exactly like /etc/hosts except for the possible third field. Now, con makes use of this information in the following way. Say you want to rsh to casbah. with con: $ con -r cas $ [alternatively] rsh casbah.acns.nwu.edu -l navarra Now, say you had a .rhosts entry for yourself on casbah and you wanted to use rsh to look at a file on a remote machine. With con, this becomes, $ con -r cas cat filename $ [alternatively] rsh casbah.acns.nwu.edu -l navarra cat filename Not good enough you say! (surely you jest). You tell me your shell has hostname completion so I can easily expand casbah. Then, con is not saving me all that much typing. Ok, I see your point. Therefore, con also uses the enviromental variable DEFAULT_OPT=/usr/ucb/rsh (that is what it is recommended to be anyway). Now, the command to check your file is now down to this: $ con cas cat filename What? Still not good enough! (my you are hard to please! ;-) Well, what if you could make a link to con, (call it say, casbah) and have con recognize what you want to do. Ok, now the command becomes $ casbah cat filename or to log in as someone else $ casbah -l jarvis or to finger someone $ casbah -F jarvis talk $ casbah -T jarvis or mail jarvis some really cool material! ;-) $ casbah -m jarvis Interesting Stuff < alt.sex.beastiality (so jarvis is kinda weird.) And there are many other cool options which all save time when typing. The con man page goes into all the excruciating detail. Con is free. However, if you want to send me money -- sure, I'll take it. I do not have any formal copyright on con -- all that legal stuff is garbage anyway. I only ask that you leave my name attached to this program. If you want to make any modifications, or have any suggestions, criticisms, ideas, etc, feel free to mail them to me. Enjoy, John Navarra navarra@nwu.edu Northwestern University #! /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 '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 casbah.acns.nwu.edu sunny 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 'aftp' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'aftp'\" else echo shar: Extracting \"'aftp'\" \(1588 characters\) sed "s/^X//" >'aftp' <<'END_OF_FILE' X#! /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(); 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; Xprint "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 if ($basename eq '*' ) { X ($dirpath = $path) =~ s!/[^/]*$!!; X printf(FTP "cd $dirpath \n"); X printf(FTP "prompt \n"); X printf(FTP "mget * \n"); X } X else { X printf(FTP "get $path $basename \n"); X } Xclose (FTP); X} X Xprint "Got it! \n "; X END_OF_FILE if test 1588 -ne `wc -c <'aftp'`; then echo shar: \"'aftp'\" unpacked with wrong size! fi chmod +x 'aftp' # 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'\" \(22079 characters\) sed "s/^X//" >'con' <<'END_OF_FILE' X#! /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# 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/u3/navarra/src/con_perl/beta1/aftp'; X$FINGER='/usr/ucb/finger'; X$FTP='/usr/ucb/ftp'; X#Mail is the default. Don't use braindead /bin/mail unless you have to. 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# make this program show up on ps as con. X$0 = $0; X X# Usage message subroutine. Xsub USAGE_MESG { X print "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(); 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()); 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# 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 #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 () { 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 } 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 } 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, your 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 "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 } X else { 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 $IP -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='' 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 'IPaddrname' 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 #call auto ftp program and get file(s). 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 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 } 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("$TALK $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 } X else { X print "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 and each domain name alias must Xbe separated by a . 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 prform 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. 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.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 XThe auto ftp program is not extraordinarily robust. If you want to use Xyour own, make sure the path is changed in the Configuration section. More Xfeatures may be added to X.I aftp Xlater. 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-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): 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.3io.nwu.edubiff" 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 22079 -ne `wc -c <'con'`; then echo shar: \"'con'\" unpacked with wrong size! fi chmod +x 'con' # end of 'con' fi if test -f 'con.man' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'con.man'\" else echo shar: Extracting \"'con.man'\" \(12318 characters\) sed "s/^X//" >'con.man' <<'END_OF_FILE' X XCON(1) USER COMMANDS CON(1) X XNAME X con - A program to facilitate contacting a host in a variety X of ways. X XSYNOPSIS X con [ -''fFhlmprRtTw ] [ hostname ] [ other ] X XDESCRIPTION X Con is a perl script that facilitates the various ways of X connecting to a machine, remote or local, by minimizing the X repetitive (and unneeded) typing one has to do to uniquely X identify a host, a login name, and an option (telnet, rlo- X gin, etc). Con is used in conjunction with a few environmen- X tal variables and a hosts file whose syntax is similiar to X /etc/hosts. X X The primary environmental variable used is HOSTSFILE which X specifies the path to a file which contains the following X information: X X IP ADDRESS domain name aliases possible username X 129.105.113.52 casbah.acns.nwu.edu cas navarra X X Each field must be separated by a and each domain name X alias must be separated by a . The HOSTSFILE need not X reside in your home directory (although that is probably X wise). For bash and/or zsh compatibility you can set X HOSTSFILE to whatever file you use for hostname completion. X X Con uses the HOSTSFILE as a reference to find the correct X computer (and possible username) to use when called with one X of many options. Thus, the user need not type the full X domain name address to connect, only enough to uniquely X identify the requested computer. For possible hosts X casbah.acns.nwu.edu and cannibal.acns.nwu.edu, the user X could identify casbah with the call 'con cas' but not with X the call 'con ca'. X X XUSAGE X Con has many different options. Some of those are used far X more than others. For that reason, con uses the variable X DEFAULT_OPT as a null option. The configuration section sets X up DEFAULT_OPT as an enviromental variable. This need not be X the case if all who use con agree on a DEFAULT_OPT. It is X recommended that rsh be used for reasons which will become X apparent later in the document. For the sake of explaining X the use of con, I will assume this is the case. X X XOPTIONS X ""|-r) rsh host [username] [commands] or X ftp [or auto ftp] host [filename] X X part 1 [rsh]: X The most common use for con will be logging into a X remote computer. The null option or -r option uses the same X syntax as rsh. The proper username to use with this option X is determined as follows: A username specified on the com- X mand line is used before any username in HOSTSFILE. To X specify a username on the command line, use the same syntax X as rsh: X X %example: con cas -l username [commands] X X If no username is specified on the commmand line, the user- X name in the third field of HOSTSFILE is used. If no username X exists in HOSTSFILE then the username on the local machine X ($USER) is used. Note: because this option always defaults X to $USER, there is no reason to put your username on local X machine as the third field in HOSTSFILE. X X Like rsh, if the name of the file from which con was exe- X cuted is anything other than ``con'', that name will be used X as its hostname argument. Thus, if a symbolic link is made X to con with a unique hostname to search for in HOSTSFILE, X that name will be used (along with any con option) to con- X nect to a host. This feature is particularly useful to cut X down on needless typing. All command lines will now be of X 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 X part 2 [ftp]: X If the username field of HOSTSFILE contains the string X 'anonymous', con will perform an ftp to the host. Con will X work in conjunction with the .netrc file to automatically X log you into the remote computer. X X If a path-to-filename is given as the last argument, con X will use the aftp [auto ftp] program which comes with the X distribution. This program will NOT use your .netrc file but X will log you in to the remote host with X 'local_username@local_host'. The filename MUST be the full X path name to the file you want to get. Aftp uses the X enviromental variable MODE (bin or ascii) to determine which X mode you want to transfer your file with. However, just as a X precaution, aftp asks for confirmation before it gets the X file. The recieved file is left in whatever directory con X was invoked from. Aftp can also get multiples files from X one directory, just include a ``*'' in the full pathname X 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 X The auto ftp program is not extraordinarily robust. If you X want to use your own, make sure the path is changed in the X Configuration section. More features may be added to aftp X later. X X -t) telnet host [port] X X A port number may be specified on the command line or as X a username in HOSTSFILE. As usual, if a port number is X specified on the command line, it will take precedence over X the username field. X X %example: con -t phoenix 25 X #telnet to mail port on phoenix.whatever X X Note: if you use telnet as a default option, the port number X ability in HOSTSFILE is lost. The number check is only made X 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 X ftp to a host. The difference is that the user may specify X directly what mode he wants the files to be transferred in X (thus bypassing confirmation by aftp ) Also, this option, X (-f), is used for hosts which are not strictly going to be X contacted for anonymous ftp (no 'anonymous' string in X HOSTSFILE). X X -F) finger [-opts] username@host X X This option is used to finger a username. Any valid X finger option can be used but must be the last argument. The X username precedence is the same as 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 -h) print out brief help screen X X This option displays a half-page help screen which shows X how the various options are used. X X -l) list host X X This option is used to check an entry in HOSTSFILE. If a X pattern is found, the relevant information on that host is X 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): X X X -m) Mail or elm [-s "Subject"] username@host [ < filename ] X X This option is used to send mail. It uses the enviro- X mental variable MAILER to determine which mail program to X use. It is recommended that either elm or Mail are used (no X other mailers have been tested so far). Again, as in all X other options, this option determines which username to use X based on the order of precedence described above. However, X if the user wants to specify a Suject on the command line, X he MUST specify a username. Otherwise, the info passed to X 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 X In the last two examples, a file was transmitted. For this X operation, con creates a subshell and the contents of X filename are sent to it to be processed 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 X options should be 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. X Because of the numerous options to traceroute, the packet- X size option is not available due to parsing problems. All X 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 X vendors are still using the braindead otalk (now who could X that be?), a -To option is available. The username pre- X cedence 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 X assumed that the user knows the relavent information nec- X cesary to make a proper entry (IP# domain alias user- X name). The entry must be enclosed in quotes with the proper X TABS between the fields. A TAB can be entered on the command X line by typing C-V TAB (control-v TAB). The entry is X appended to the end of HOSTSFILE. X X %example: con -w "129.10.11.3io.nwu.edubiff" X X Con also provides a more user-friendly way to make entries X in HOSTSFILE. If the environmental variable CHECK_HOST is X set to ``yes'', then for any hostname pattern entered on the X command line not found in HOSTSFILE, the user will be X prompted if he wants to make an entry. The process is demon- X strated as follows: X X [casbah:112] ~ -> con cas X No pattern in hostfile. Do you want to make an entry [yes] X ok, your will be prompted separately for a domain name X with aliases, an IP address, and a possible username. X Enter info or hit return to accept [cas] casbah.acns.nwu.edu X Enter info or hit return to accept [129.105.113.52] X Enter info or hit return to accept [] fred X Accept: 129.105.113.52 casbah.acns.nwu.edu fred [yes] X X Note that the IP address is resolved if given a legiti- X mate domain name. In that way, the user just needs to X hit RETURN to accept the address and con will make sure X it is written correctly to HOSTSFILE. Note also the the X default username is nothing (fred was used in the exam- X ple). X X X XENVIRONMENTAL VARIABLES X HOSTSFILE X DEFAULT_OPT X CHECK_HOST X MAILER X MODE X XFILES X $HOME/$HOSTSFILE X ./aftp (auto ftp program) X XAUTHOR X John Navarra (navarra@nwu.edu) X Academic Computing and Networking Services X Northwestern University X XBUGS X There are probably a few bugs here and there. I have only X tested con on a SunOS and Mach machines. I am interested in X hearing about any bugs and suggestions for improvement. X END_OF_FILE if test 12318 -ne `wc -c <'con.man'`; then echo shar: \"'con.man'\" unpacked with wrong size! fi # end of 'con.man' 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 chmod +x 'sample_hostsfile' # end of 'sample_hostsfile' fi echo shar: End of shell archive. exit 0