From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21790 invoked from network); 29 Jun 1998 21:47:49 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 29 Jun 1998 21:47:49 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id RAA13096; Mon, 29 Jun 1998 17:43:18 -0400 (EDT) Resent-Date: Mon, 29 Jun 1998 17:40:49 -0400 (EDT) From: "Bart Schaefer" Message-Id: <980629144154.ZM5213@candle.brasslantern.com> Date: Mon, 29 Jun 1998 14:41:54 -0700 In-Reply-To: <199806292026.QAA10696@ocalhost> Comments: In reply to Timothy J Luoma "Is there a way to find the Remote Host in ZSH?" (Jun 29, 4:26pm) References: <199806292026.QAA10696@ocalhost> X-Mailer: Z-Mail Lite (5.0.0 30July97) To: Timothy J Luoma , zsh-users@math.gatech.edu Subject: Re: Is there a way to find the Remote Host in ZSH? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"FrjuQ2.0.7A3.Wd0cr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1658 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Jun 29, 4:26pm, Timothy J Luoma wrote: > Subject: Is there a way to find the Remote Host in ZSH? > > I am looking for a way to get the complete hostname or IP address where I > have connected _from_ when making a telnet/ssh/etc connection. There really isn't any good way to do this from the shell, AFAIK. If you have the descriptor of the socket on which the connection is established, you can use the getpeername() call from a C program, but that descriptor may be hard to get at by the time you have a running shell. The closest you can probably get is parsing or grepping the output from "netstat", but that'll show you -all- connections without any way to tell for sure which one of them is yours, so you'd be doing a bit of guessing. It may not be unmanageable if you're unlikely to be logged in to the same place twice and no one else from your local machine is likely to be logged in to the same remote one. A -very- crude approximation would be if netstat -tn | grep -sw 123\\.123\\.12\\.3; then : whatever fi > Something like REMOTE_IP or REMOTE_HOSTNAME (I think tcsh has something > like that). I can't find any mention thereof in the tcsh man page; all I could find was the %M format for the "who" variable, which reads the utmp file same as "who am I".