Know my the IP/interface being used by current tty/shell
Know my the IP/interface being used by current tty/shell
am 09.01.2008 18:39:59 von A Ferenstein
I've asked on comp.unix.solaris, but no luck.
I have a host with multiple interfaces; I wish to know the IP (belonging to
one of the these multiple interfaces) is being use by my current tty/shell
(started via rsh, ssh, telnet, etc) - how can I find out?
(In simplest form - let's say I forgot to which IP addresses I telnet'd to -
how can I find out at the remote end shell prompt?)
Thanks
(PS. "who am i" gives me originator's IP, but I wish to find out my own)
Re: Know my the IP/interface being used by current tty/shell
am 09.01.2008 19:14:12 von Icarus Sparry
On Thu, 10 Jan 2008 04:39:59 +1100, Alex Ferenstein wrote:
> I've asked on comp.unix.solaris, but no luck. I have a host with
> multiple interfaces; I wish to know the IP (belonging to one of the
> these multiple interfaces) is being use by my current tty/shell (started
> via rsh, ssh, telnet, etc) - how can I find out? (In simplest form -
> let's say I forgot to which IP addresses I telnet'd to - how can I find
> out at the remote end shell prompt?) Thanks
> (PS. "who am i" gives me originator's IP, but I wish to find out my own)
For ssh, you can look at the SSH_CONNECTION environment variable.
In general you can not find this information in a portable way. For
example when you telnet to a box typically inetd (or some varient)
accepts the connection, then invokes in.telnetd or telnetd. At this point
either inetd could put into the environment the details of the
connection, or else telnetd could use a function (e.g. getsockname) on
its standard input and put the infomation into the environment.
Then telnetd will allocate a pty, and start a shell. This shell has no
direct connection to the incoming socket, it is connected to the pty.
You *may* be able to find this information in other ways, for example you
might be able to find your parent process id, and then have something
like /proc/$PPID/fd/0 available to you.
The same description is true for using "rshell".
For "rsh" the situation is slightly different. If you use "rsh host" then
this is turned into "rshell host". If you use "rsh host command" then no
pty is allocated and you can write a program that uses getsockname to
find the local address.
Re: Know my the IP/interface being used by current tty/shell
am 09.01.2008 21:05:23 von PK
Alex Ferenstein wrote:
> (In simplest form - let's say I forgot to which IP addresses I telnet'd to
> - how can I find out at the remote end shell prompt?)
Probably not what you were looking for...but anyway:
netstat -tn | grep $your_origin_address | awk '{ print $4 }'
This is *really* basic and needs refinement (for example, the grep match can
be improved, and the output must be "purified")...but I hope you got the
idea.
Re: Know my the IP/interface being used by current tty/shell
am 09.01.2008 22:56:49 von Alex Ferenstein
On Jan 10, 5:14=A0am, Icarus Sparry wrote:
> On Thu, 10 Jan 2008 04:39:59 +1100, Alex Ferenstein wrote:
> > I've asked on comp.unix.solaris, but no luck. I have a host with
> > multiple interfaces; I wish to know the IP (belonging to one of the
> > these multiple interfaces) is being use by my current tty/shell (started=
> > via rsh, ssh, telnet, etc) - how can I find out? (In simplest form -
> > let's say I forgot to which IP addresses I telnet'd to - how can I find
> > out at the remote end shell prompt?) Thanks
> > (PS. "who am i" gives me originator's IP, but I wish to find out my own)=
>
> For ssh, you can look at the SSH_CONNECTION environment variable.
Yes, this is what I was after.. However, it's a pity I can't get same
from telnet and rsh.
With a multi-interfaced hosts accessed via a Load Balancer, obtaining
own destination IP is quite important - I don't see why Sun don't
provide a (separate) utility.
Re: Know my the IP/interface being used by current tty/shell
am 10.01.2008 08:01:20 von Icarus Sparry
On Wed, 09 Jan 2008 13:56:49 -0800, Alex Ferenstein wrote:
> On Jan 10, 5:14Â am, Icarus Sparry wrote:
>> On Thu, 10 Jan 2008 04:39:59 +1100, Alex Ferenstein wrote:
>> > I've asked on comp.unix.solaris, but no luck. I have a host with
>> > multiple interfaces; I wish to know the IP (belonging to one of the
>> > these multiple interfaces) is being use by my current tty/shell
>> > (started via rsh, ssh, telnet, etc) - how can I find out? (In
>> > simplest form - let's say I forgot to which IP addresses I telnet'd
>> > to - how can I find out at the remote end shell prompt?) Thanks (PS.
>> > "who am i" gives me originator's IP, but I wish to find out my own)
>>
>> For ssh, you can look at the SSH_CONNECTION environment variable.
>
> Yes, this is what I was after.. However, it's a pity I can't get same
> from telnet and rsh.
Pity you snipped out so much of my reply, where I explained he issue.
You also left off the explanation that "rsh" probaly ment "rshell" in
this case.
If you administer your machines then you have a number of options.
The simplest is to use tcp_wrapper, and get it to add some extra
variables into the environment. See hosts_options in section 5 of the
manual. tcp_wrapper can be obtained from a large number of sites on the
Internet.
You could replace inetd with Dan Bernstein's tools, see http://cr.yp.to.
> With a multi-interfaced hosts accessed via a Load Balancer, obtaining
> own destination IP is quite important - I don't see why Sun don't
> provide a (separate) utility.
I don't see why everyone in Australia doesn't each send me $10. I think
this is more important. You are free to disagree.