SUMMARY: Remote Login

From: Wes Boudville (
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:

[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;
                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

# displayhost by (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
set `who am i`

# if not remotely logged in
if [ "$host" = "" ]
        echo $host

# 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
set $host_socket
eval socket=\$$#

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

# split $hostip_socket into parts
set $hostip_socket

# use hostip parts to get hostname from nslookup
nslookup << EOF | grep -e | awk '{ print $5 }'
        set type=any

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