PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Know my the IP/interface being used by current tty/shell
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Know my the IP/interface being used by current tty/shell

Réponse
 
LinkBack Outils de la discussion
Vieux 09/01/2008, 17h39   #1
Alex Ferenstein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Know my the IP/interface being used by current tty/shell

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)

  Réponse avec citation
Vieux 09/01/2008, 18h14   #2
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Know my the IP/interface being used by current tty/shell

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.
  Réponse avec citation
Vieux 09/01/2008, 20h05   #3
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Know my the IP/interface being used by current tty/shell

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.

  Réponse avec citation
Vieux 09/01/2008, 21h56   #4
Alex Ferenstein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Know my the IP/interface being used by current tty/shell

On Jan 10, 5:14am, Icarus Sparry <use...@icarus.freeuk.com> 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.
  Réponse avec citation
Vieux 10/01/2008, 07h01   #5
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Know my the IP/interface being used by current tty/shell

On Wed, 09 Jan 2008 13:56:49 -0800, Alex Ferenstein wrote:

> On Jan 10, 5:14Âam, Icarus Sparry <use...@icarus.freeuk.com> 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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h20.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10866 seconds with 13 queries