SUMMARY: Remote Login

From: Wes Boudville (wes@cco.caltech.edu)
Date: Fri Apr 02 1993 - 11:22:34 CST


I asked recently:

> Suppose I rlogin to a Sun4. I want to find either the hostname or
> the IP address of the computer that I'm logging in from. Any ideas?
> More specifically, how can I get the number of the socket that is
> assigned to my remote login by the server Sun? If I know this, then I
> can call getpeername to find the client address.
> Unfortunately, parsing the output of 'who', which looks at /etc/utmp,
> is not reliable. If I rlogin to the sun from a machine with a long name,
> then the name will be truncated in /etc/utmp.
> Please note that anything I try must be as a regular user. I do not
> have root privileges.
> This is frustrating. Clearly, if I successfully rlogin, then the
> system knows where I'm coming from. But how do I get at this information?
> [I suspect that to anyone who knows sockets well, this is trivial.]

Thanks for the many replies:

        miesch@bns101.caltech.edu
        hendefd@tech.duc.auburn.edu
        Anthony.Worrall@reading.ac.uk
        heiser@tdwr.ed.ray.com
        bboards@optical.bms.com
        eckhard@ts.go.dlr.de
        macelis@neb.com
        barmar@think.com
        yves.morin@bcomeau.hydro.qc.ca
        stanonik@nprdc.navy.mil
        hkatz@nucmed.med.nyu.edu
        schnitz@unipress.com
        oday@hercules.calspan.com
        fox@crisp.demon.co.uk
        Perry_Hutchison.Portland@xerox.com
        arogers@eng.umd.edu
        b.keck@trl.oz.au
        gwh@ecliptic.stat.nielsen.com
        B.C.Hamshere@newcastle.ac.uk
        don@mars.dgrc.doc.ca

[Sorry about sending 2 requests to sun-managers. The 1st one was
delayed so I thought it got lost.]

Apparently, someone had asked a similar question last year.

The answers I got fell into several categories:

a. Outrightly Wrong
        ----------------

'ifconfig -a'. This has no info about remote machines.

b. [Somewhat] Wrong
        ----------------

'arp -a'. The remote machine may not be listed.

'rusers -l'
'last `whoami` ...'
Various parsings of `who`
                These all have the same problem as I originally
                described. If the remote machine has a name>16
                chars long, it will be truncated.

struct sockaddr_in sa;
struct hostent *hp;
getpeername(0,&sa,&sizeof(sa));
hp=gethostbyaddr(...)
                This is in the source code for rshd and rlogind.
                I got "not a socket" error message when I ran it
                in my program. I dont know why it should fail here
                while it works in rshd or rlogind.

c. Correct
        -------

#================================================================
#!/bin/sh
#
# displayhost by don@mars.dgrc.doc.ca (Donald McLachlan), 11/12/92
#
# USAGE: setenv DISPLAY `displayhost`:0

#
# get name of remote host from `who am i` (as in utmp/wtmp/lastlog)
# $host will be null, if not remotely logged in
#
IFS_OLD=$IFS
IFS=$IFS\(\)
set `who am i`
host=$6
IFS=$IFS_OLD

#
# if not remotely logged in
#
if [ "$host" = "" ]
then
        host=`hostname`
        echo $host
        exit
fi

#
# use $host to get a login host.socket pair from netstat
#
host_socket=`netstat | awk '{ print $5 }' | awk '/\.[0-9]+$/ { print }' | fgrep $host | head -1`

#
# get socket from $host_socket pair
#
IFS=$IFS.
set $host_socket
eval socket=\$$#
IFS=$IFS_OLD

#
# use $socket to get hostip.socket pair from netstat
#
set `netstat -n | grep $socket`
hostip_socket=$5

#
# split $hostip_socket into parts
#
IFS=$IFS.
set $hostip_socket
IFS=$IFS_OLD

#
# use hostip parts to get hostname from nslookup
#
nslookup << EOF | grep -e in-addr.arpa | awk '{ print $5 }'
        set type=any
        $4.$3.$2.$1.in-addr.arpa
EOF
#================================================================

Several blokes pointed out that it is not trivial to access the
socket info. It would certainly be possible to modify rlogind
to pass more info into the login environment. But I cannot assume
that I have root access.



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:07:40 CDT