Determining Local IP Address within .profile

Dan Kaminsky dan at doxpara.com
Thu Sep 5 00:56:45 EST 2002


mario paumann wrote:

>Thanx dan, but i mean it as i wrote it.
>
>I need the local ip not the remote ip (which is in SSH_CLIENT).
>  
>
Actually, that's an interesting problem, deserving of your solution.

Right now, we expose:

SSH_CLIENT='10.0.1.37 3985 22'

Technically, this can be used to discover the local socket IP by 
querying lsof using this genuinely hideous shell script:

#!/bin/sh

REMHOST=`echo $SSH_CLIENT | cut -f1 -d" "`
REMPORT=`echo $SSH_CLIENT | cut -f2 -d" "`
LOCPORT=`echo $SSH_CLIENT | cut -f3 -d" "`

lsof -n -i TCP@$REMHOST:$REMPORT | cut -b57-99 | cut -d':' -f1 | grep -v 
NAME

This won't work for any security critical systems (end users can select 
their local port and thus impersonate existing sessions, though this can 
be checked for by counting the number of lines returned), but it does 
have the advantage of working on existing systems.

Yes, your method is much nicer though, and I'd actually support a new 
environment variable -- SSH_SERVER -- to contain the IP of the incoming 
socket.

--Dan





More information about the openssh-unix-dev mailing list