Operating System - HP-UX
1748076 Members
5330 Online
108758 Solutions
New Discussion

Re: Issue obtaining the users IP

 
SOLVED
Go to solution
Simon Hargrave
Honored Contributor
Solution

Re: Issue obtaining the users IP

Okay, I have another plan, which stems from some work I've had to do recently.

Not sure why your backticks don't work, but the who command won't work anyway because you're not attached to a tty.

So, I got thinking about this, and you can do it with the lsof command. ( you can download lsof from http://hpux.connect.org.uk/hppd/hpux/Sysadmin/lsof-4.72/ )

Basically the theory is, you run lsof against your own process, and extract the line that says what STDIN (stream 1) is attached to. This will be an inet entry which will show the source and destination ip/ports. You can then extract these.

In your example, I'd suggest adding the following line to httpd.sh: -

IP=$(/usr/bin/getip $(/usr/local/bin/lsof -p $$ | grep -w "1u" | cut -d\> -f2 | cut -d: -f1))

You can then pass $IP to your binary as a parameter.

Perhaps first verify it's working with echo $IP >> /tmp/http.access.log and make sure that file gets filled with IP addresses as you access the service.

I used this in a wrapper script to log connections to inetd services that aren't clever enough to log connection attempts. I basically run a wrapper which writes ip address, date, service etc to a logfile, then pass through to the actual server daemon process.

Jay LaBonte
Advisor

Re: Issue obtaining the users IP

Thank You!

The lsof gave me excactly what I needed.

Thanks Again.
Jay