zsh-users
 help / color / mirror / code / Atom feed
* Is there a way to find the Remote Host in ZSH?
@ 1998-06-29 20:26 Timothy J Luoma
  1998-06-29 21:35 ` Sweth Chandramouli
  1998-06-29 21:41 ` Bart Schaefer
  0 siblings, 2 replies; 5+ messages in thread
From: Timothy J Luoma @ 1998-06-29 20:26 UTC (permalink / raw)
  To: zsh-users


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.

Right now the only thing I can figure out is 'who am i' which doesn't always  
give enough information:

kira!luomat   ttypb    Jun 29 13:16 (cc344191-a.ewnds)

The hostname is the last field, but it isn't complete and I'd prefer not to  
have to do

	REMOTE_HOSTNAME=`who am i | awk '{print $NF}' | tr -d '(|)'`

which is what I am currently using.

Anyway, I have some settings I would like to make specific to when I connect  
from certain IPs, so this would be helpful....

if [ "$REMOTE_IP" = "123.123.12.3" ]; then
	source specialfile
fi	

Something like REMOTE_IP or REMOTE_HOSTNAME (I think tcsh has something like that).

Is there a way to do this already that I just don't know about?

TjL



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Is there a way to find the Remote Host in ZSH?
  1998-06-29 20:26 Is there a way to find the Remote Host in ZSH? Timothy J Luoma
@ 1998-06-29 21:35 ` Sweth Chandramouli
  1998-06-29 22:31   ` Bart Schaefer
  1998-06-29 21:41 ` Bart Schaefer
  1 sibling, 1 reply; 5+ messages in thread
From: Sweth Chandramouli @ 1998-06-29 21:35 UTC (permalink / raw)
  To: zsh-users

On Mon, Jun 29, 1998 at 04:26:56PM -0400, Timothy J Luoma wrote:
> 
> 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.
[snip]
> Is there a way to do this already that I just don't know about?
	
	it looks like it; on my machine, at least, i have REMOTE_HOSTNAME
and REMOTE_IPADDRESS defined when i log in:

(astaroth)~: set | grep 'REMOTE'
REMOTE_HOSTNAME=simon
REMOTE_IPADDRESS=208.135.210.91

	those aren't being set in any of the system-wide scripts or in
any of my personal ones, so i'm assuming that they are set by the shell.
the sad thing is that until you asked this, i was using an even uglier
kludge than yours to pull my remote host from the lastlog.

	on a mildly related note, does anyone know if wtmpx (on solaris,
at least) stores the full name of the remote host, and last/finger simply
truncates it?  the manpage on wtmpx defines ut_host as char ut_host[257];
i don't know any c, but assume this means that it is a 257-byte character
field.

	-- sweth.

-- 
Sweth Chandramouli
IS Coordinator, The George Washington University
<sweth@gwu.edu> / (202) 994 - 8521 (V) / (202) 994 - 0458 (F)
<a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Is there a way to find the Remote Host in ZSH?
  1998-06-29 20:26 Is there a way to find the Remote Host in ZSH? Timothy J Luoma
  1998-06-29 21:35 ` Sweth Chandramouli
@ 1998-06-29 21:41 ` Bart Schaefer
  1 sibling, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 1998-06-29 21:41 UTC (permalink / raw)
  To: Timothy J Luoma, zsh-users

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Is there a way to find the Remote Host in ZSH?
  1998-06-29 21:35 ` Sweth Chandramouli
@ 1998-06-29 22:31   ` Bart Schaefer
  1998-06-29 22:58     ` Geoff Raye
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 1998-06-29 22:31 UTC (permalink / raw)
  To: zsh-users

On Jun 29,  5:35pm, Sweth Chandramouli wrote:
> 	
> 	it looks like it; on my machine, at least, i have REMOTE_HOSTNAME
> and REMOTE_IPADDRESS defined when i log in:
> 
> (astaroth)~: set | grep 'REMOTE'
> REMOTE_HOSTNAME=simon
> REMOTE_IPADDRESS=208.135.210.91
> 
> 	those aren't being set in any of the system-wide scripts or in
> any of my personal ones, so i'm assuming that they are set by the shell.

Are they set regardless of whether you rlogin/rsh/telnet/ssh to the remote
machine?

They could be being set by the rlogin daemon or some such, before the shell
is even started.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Is there a way to find the Remote Host in ZSH?
  1998-06-29 22:31   ` Bart Schaefer
@ 1998-06-29 22:58     ` Geoff Raye
  0 siblings, 0 replies; 5+ messages in thread
From: Geoff Raye @ 1998-06-29 22:58 UTC (permalink / raw)
  To: zsh-users

["Bart Schaefer"]
>On Jun 29,  5:35pm, Sweth Chandramouli wrote:
>> 	it looks like it; on my machine, at least, i have REMOTE_HOSTNAME
>> and REMOTE_IPADDRESS defined when i log in:
>> 
>> (astaroth)~: set | grep 'REMOTE'
>> REMOTE_HOSTNAME=simon
>> REMOTE_IPADDRESS=208.135.210.91
>> 
>> 	those aren't being set in any of the system-wide scripts or in
>> any of my personal ones, so i'm assuming that they are set by the shell.
>
>Are they set regardless of whether you rlogin/rsh/telnet/ssh to the remote
>machine?
>
>They could be being set by the rlogin daemon or some such, before the shell
>is even started.

As an example, ssh sets SSH_CLIENT='ip.you.are.from srcport localport',
which would be quite adequate for your uses.  As long as you're doing this
for customization, rather then security, it'd work quite nicely to parse
out the IP.

I'd guess that REMOTE_* are being set by some program you're using to
connect.  (Neither rsh, telnet, nor ssh seem to do so on BSDi, so I'm
not sure what you're using.)

I'd tend to hold the login daemon responsible.

Geoff

-- 
Geoff Raye           - geoff@raye.com          - MEoW!
System Administrator - Neoglyphics Media Corp. - PGP: finger raye@uiuc.edu


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1998-06-29 23:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-29 20:26 Is there a way to find the Remote Host in ZSH? Timothy J Luoma
1998-06-29 21:35 ` Sweth Chandramouli
1998-06-29 22:31   ` Bart Schaefer
1998-06-29 22:58     ` Geoff Raye
1998-06-29 21:41 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).