Am I on a telnet session ?

Am I on a telnet session ?

Post by jor » Mon, 28 Jan 2002 14:40:00



Is there a command or any way I can use to see if I'm on a telnet session ?

Thanks

 
 
 

Am I on a telnet session ?

Post by Dave Good » Mon, 28 Jan 2002 17:52:05



> Is there a command or any way I can use to see if I'm on a telnet session

Well, you could try 'hostname'. If the result isn't the host you're sat at
then you must be logged in somewhere else.

Dave
--
www.davegoode.net

 
 
 

Am I on a telnet session ?

Post by Dr. Yuan Li » Tue, 29 Jan 2002 06:07:15


Definitely.  Standard telnet implementation has an "escape" command;
usually this is ^].  Press Ctrl and ] to see if your session returns to
telnet> prompt.  The "escape" sequence is definable, so if you are in
deep telnet loops, you can define a different sequence for each session.

Understandably, DO$ and Windo$e versions of telnet don't always support
this.

Yuan Liu


> Is there a command or any way I can use to see if I'm on a telnet session ?

> Thanks

 
 
 

Am I on a telnet session ?

Post by jor » Tue, 29 Jan 2002 16:17:39


Thanks for the reply Dr. Liu, but I don't think I was very clear in my
question.. I'd like to run a command in a "shell script" to determine
if the current environment is a telnet session...

The reason I ask is because I'd like my .logout file to perform some
actions when logging out of my X session, and different actions if i'm
logging out of a telnet session...

Can you think of any way I might do that ?

thanks,
Jorr


> Definitely.  Standard telnet implementation has an "escape" command;
> usually this is ^].  Press Ctrl and ] to see if your session returns to
> telnet> prompt.  The "escape" sequence is definable, so if you are in
> deep telnet loops, you can define a different sequence for each session.

> Understandably, DO$ and Windo$e versions of telnet don't always support
> this.

> Yuan Liu


> > Is there a command or any way I can use to see if I'm on a telnet session ?

> > Thanks

 
 
 

Am I on a telnet session ?

Post by Igor Istlentie » Tue, 29 Jan 2002 16:42:46



> Thanks for the reply Dr. Liu, but I don't think I was very clear in my
> question.. I'd like to run a command in a "shell script" to determine
> if the current environment is a telnet session...

> The reason I ask is because I'd like my .logout file to perform some
> actions when logging out of my X session, and different actions if i'm
> logging out of a telnet session...

> Can you think of any way I might do that ?

> thanks,
> Jorr

1. You need know your IP-address.
2. See the output of 'netstat -n' command. Find the string contain your
IP-address in "Foreign Address" column. Then see the port number in
"Local Address" column. If this port is 23 you connect via telnet.

--
Best regards,
Igor Istlentiev
Voronezh Savings Bank

 
 
 

Am I on a telnet session ?

Post by Dr. Yuan Li » Tue, 29 Jan 2002 18:18:07


Indeed.  Igor showed how to get this from netstat.  Some versions of w
displays a column called "from", like this:
$ w $USER
05:32  up 38 days, 20:30,  2 users,  load average: 0.00, 0.00, 0.00

yliu     p1         xxxxxxxxx        05:31                        w

The xxxxxxxxx part would be "console" or null if you are on the
console/terminal, but would be your foreign host if you are remote.

last command also indicates your foreign host, if your system has it:
$ last -1
yliu      ttyp1        xxxxxxxxx   Mon Jan 28 05:31   still logged in

You can look at the third column (xxxxxxxxx).  It will have a null value
or "console" if you are not remote.

If you are using ssh instead of telnet, OpenSSH sets a local variable
SSH_CLIENT.

$ if [ $SSH_CLIENT ]; then echo I am from SSH.; fi

This works in your login shell.  If you want to use it in a script, you
must first modify your .profile or .login to export it to the
environment. (Maybe .logout is executed as ., so export may not be
necessary there.)

Yuan Liu


> Thanks for the reply Dr. Liu, but I don't think I was very clear in my
> question.. I'd like to run a command in a "shell script" to determine
> if the current environment is a telnet session...

> The reason I ask is because I'd like my .logout file to perform some
> actions when logging out of my X session, and different actions if i'm
> logging out of a telnet session...

> Can you think of any way I might do that ?

> thanks,
> Jorr

 
 
 

Am I on a telnet session ?

Post by Igor Istlentie » Tue, 29 Jan 2002 20:00:44



> Indeed.  Igor showed how to get this from netstat.  Some versions of w
> displays a column called "from", like this:
> $ w $USER
> 05:32  up 38 days, 20:30,  2 users,  load average: 0.00, 0.00, 0.00

> yliu     p1         xxxxxxxxx        05:31                        w

> The xxxxxxxxx part would be "console" or null if you are on the
> console/terminal, but would be your foreign host if you are remote.

> last command also indicates your foreign host, if your system has it:
> $ last -1
> yliu      ttyp1        xxxxxxxxx   Mon Jan 28 05:31   still logged in

> You can look at the third column (xxxxxxxxx).  It will have a null value
> or "console" if you are not remote.

> If you are using ssh instead of telnet, OpenSSH sets a local variable
> SSH_CLIENT.

> $ if [ $SSH_CLIENT ]; then echo I am from SSH.; fi

> This works in your login shell.  If you want to use it in a script, you
> must first modify your .profile or .login to export it to the
> environment. (Maybe .logout is executed as ., so export may not be
> necessary there.)

> Yuan Liu

Yuan Liu, the output's format of w command is system depended. For
example, in SCO OpenServer column with IP-address has number 7. Then I
can't see via this output my connection service - telnet, ssh, X etc
etc.

--
Best regards,
Igor Istlentiev
Voronezh Savings Bank

 
 
 

Am I on a telnet session ?

Post by Dr. Yuan Li » Wed, 30 Jan 2002 05:43:08




> > Indeed.  Igor showed how to get this from netstat.  Some versions of w
> > displays a column called "from", like this:
> > $ w $USER
> > 05:32  up 38 days, 20:30,  2 users,  load average: 0.00, 0.00, 0.00

> > yliu     p1         xxxxxxxxx        05:31                        w

> Yuan Liu, the output's format of w command is system depended. For
> example, in SCO OpenServer column with IP-address has number 7. Then I
> can't see via this output my connection service - telnet, ssh, X etc
> etc.

That's why I said some versions support this.  I noticed this column
only after Linux/Gnu, but apparently some commercial Unix' decided to
adapt to this.  Digital Unix/True 64, for one, displays "from"; yet
Solaris doesn't.  However, on systems that don't, some use pseudo tty
service (commonly pts) for remote connections, so you can differentiate
from the TTY service used.  For example, if I'm logged in remotely on
Solaris, I get:
$ w $USER
 12:19pm  up 177 day(s), 19:41,  1 user,  load average: 0.01, 0.02, 0.02

yliu     pts/0        12:12pm            2         w yliu

whereas if I'm on the console, the TTY would be tty0, etc. (X-terminals,
even if emulated locally, are always remote - but then, you can't logout
from an X-terminal.)

Interestingly enough, "who" provides your connection on Solaris:
$ who -m
yliu       pts/0        Jan 28 12:12    (xxxxxxxxxx)

There may be some coordination between w and who so one will display
this:-)

Yuan Liu

 
 
 

Am I on a telnet session ?

Post by Igor Istlentie » Wed, 30 Jan 2002 18:03:30



> That's why I said some versions support this.  I noticed this column
> only after Linux/Gnu, but apparently some commercial Unix' decided to
> adapt to this.  Digital Unix/True 64, for one, displays "from"; yet
> Solaris doesn't.  However, on systems that don't, some use pseudo tty
> service (commonly pts) for remote connections, so you can differentiate
> from the TTY service used.

In SCO OpenServer used /dev/ttyp for pseudo-terminals naming.

> For example, if I'm logged in remotely on
> Solaris, I get:
> $ w $USER
>  12:19pm  up 177 day(s), 19:41,  1 user,  load average: 0.01, 0.02, 0.02

> yliu     pts/0        12:12pm            2         w yliu

> whereas if I'm on the console, the TTY would be tty0, etc. (X-terminals,
> even if emulated locally, are always remote - but then, you can't logout
> from an X-terminal.)

I guess, you use csh. In sh used LOGNAME variable.
Quote:

> Interestingly enough, "who" provides your connection on Solaris:
> $ who -m
> yliu       pts/0        Jan 28 12:12    (xxxxxxxxxx)

Yes, it's equiv to command 'who am i'. BTW, if I connect via X string
xxxxx contain in really DISPLAY value:
$ who am i
ist     pts/3   Jan 29 11:18    (ist:0.0)

If I connect via telnet:
$ who am i
ist     pts/5   Jan 29 11:20    (ist)

So, the author of originate message can used this value for analyze
telnet or X.

--
Best regards,
Igor Istlentiev
Voronezh Savings Bank

 
 
 

Am I on a telnet session ?

Post by those who know me have no need of my nam » Thu, 31 Jan 2002 11:44:53



Quote:>Is there a command or any way I can use to see if I'm on a telnet session ?

who might.  it's also possible that a combination of environment variables
provides the information you are looking for.

--
okay, have a sig then

 
 
 

Am I on a telnet session ?

Post by Mohi » Thu, 07 Feb 2002 18:21:35




> >Is there a command or any way I can use to see if I'm on a telnet session ?

> who might.  it's also possible that a combination of environment variables
> provides the information you are looking for.

Hi,

There is a way to this:

Do ps -$LOGNAME and take the parent shells PID
for eg:
$ ps -eaf|grep $LOGNAME
  raghua 24001 23386  7 20:27:36 ttyq6     0:00 ps -eaf  
  raghua 13954 13953  0 20:23:00 ttyq6     0:00 -sh        

Then grep for that PID like shown below, if it has telnetd as a
process name then it shows that it's a telnet session.

$ ps -eaf|grep "13953"
    root 13953   933  0 16:35:39 ttyq6     0:00 telnetd
     ABC 13954 13953  0 16:35:39 ttyq6     0:00 -sh

This solution is reliable. Please do not use "w" it will work only if
you invoke telnet process from the UNIX Server.

Mohit Anchlia

 
 
 

1. Session disconnects in a telnet session

I am getting connected to a Red Hat Linux 6.0 box thru a telent session in
winodws NT. After around 20-30 min of inactivity with the telnet session,
Linux automatically closes the session. Is there a parameter to change this
time or disable this feature.

Normally there is a TMOUT that can be set in profile but I don't see it in
the profile (not in the /etc/profile too). I am using /bin/ksh as my default
shell.

Thanks for your help.

2. Bus error (core dumped)

3. --> Session disconnects in a telnet session <--

4. tar on digital unix 4.0D

5. Difference between XWindows session and telnet session

6. Q: Solaris modinfo

7. view a tty console session from a telnet session.

8. You have mail

9. Starting X session from telnet session

10. PPP/Telnet - What tty invoked a telnet session?

11. Telnet - What am I doing wrong?

12. find and increase telnet sessions??

13. limiting telnet sessions/user