Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Is there a way to find the Remote Host in ZSH?



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".



Messages sorted by: Reverse Date, Date, Thread, Author