Operating System - Linux
1753451 Members
6067 Online
108794 Solutions
New Discussion юеВ

who can show my one simple script to get my current login IP?

 
SOLVED
Go to solution
Michael Creutz
Advisor

Re: who can show my one simple script to get my current login IP?

I use:

echo $SSH_CLIENT | cut -d " " -f 1

Jared Middleton
Frequent Advisor

Re: who can show my one simple script to get my current login IP?

echo $HOSTNAME works for me too on Red Hat 7.3 Professional, connected via CRT Telnet.

$ uname -a
Linux 2.4.20-20.7bigmem #1 SMP Mon Aug 18 14:34:37 EDT 2003 i686 unknown
Jared Middleton
Frequent Advisor

Re: who can show my one simple script to get my current login IP?

nuts, sorry about the typo. Of course, I meant "echo $REMOTEHOST" works for me.
Ross Minkov
Esteemed Contributor

Re: who can show my one simple script to get my current login IP?


I have the following in my .bash_profile. This returns hostname:0.0.

predis=`/usr/bin/who -m --lookup | /bin/grep "(" | /bin/sed "s/^.*(\(.*\))/\1:0.0/" | /bin/cut -d: -f1,2`
if [ "$predis" != "" ]; then
echo "Setting DISPLAY to $predis"
DISPLAY=$predis
export DISPLAY
fi

If you want it to return IP you can try adding something like this:

ipa=`/usr/bin/host $predis /bin/cut -d" " -f4`

and remove the :0.0 part at the end...

HTH,
Ross

Claudio Cilloni
Honored Contributor

Re: who can show my one simple script to get my current login IP?

I was connecting through telnet. I relize now that ssh didn't set the REMOTEHOST variable. It gives SSH_CLIENT and SSH_CONNECTION.

ciao,
Claudio