Determine My IP Address


I'm writing a perl script for firewall configuration and I need a way of determining my ip address into a variable.

Ie: The ip address of the person telnetted / ssh'd into the system and running the script.
LVL 18
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

and which exactly is the address you need???
netstat and ifconfig may become useful when combined with awk
PluckaAuthor Commented:
As above the IP address of the user running the script.
ahh, so
for remote only:
$ who am i | awk -F" " '// { print $4}'
and same for ssh only:
SSH_CLIENT variable is set by OpenSSH server(disable telnet NOW)
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

$ id -p
shows if su has been used...
PluckaAuthor Commented:

That doesnt work cause my server returns a DNS name in the who am i bit, I used to do that.

From your other post I can get the IP address by doing

netstat -n | grep ''

Which shows me the connection on port 22 to the server This returns.

tcp4       0     20    ESTABLISHED

which using your awk example i can do this.

netstat -n | grep '' | awk -F" " '// { print $5}'

which gives me

So i'm almost there, have little experience with awk, can you help me with the awk command to pull off the last .4895 bit.
PluckaAuthor Commented:
Ok if I add

netstat -n | grep '' | awk -F" " '// { print $5}' -F"." '// {print $1$2$3$4}'

I get the ip address without the .'s ie ( is shown as 192168160)  
no need for grep:
netstat -n | awk -F" " '/ { print $5}' -F"." '// {print $1.$2.$3.$4}'
now you tell you have only ssh:

echo $SSH_CLIENT | awk '// {print $1}'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.