Determining Local IP Address within .profile

Darren Tucker
Wed, 04 Sep 2002 14:17:13 -0000

Mario Paumann wrote:
> I haven't found an easy solution to determine the local IP to which
> the remote SSH client is connected to the local SSHD. We use
> MC/Serviceguard which can create many Interfaces where a remote client
> could connect and we like to know within .profile which interface the
> client has connected to.

I think patching sshd to provide a $SSH_SERVER variable is cleaner, but
you could use the the client IP and port to look up the matching local
ip/port pair via netstat, eg:

remote=`echo $SSH_CLIENT | awk '{print $1":"$2}'`
local=`netstat -n | awk '/'$remote'/{print $4}'`

--
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4  37C9 C982 80C7 8FF4 FA69
    Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.