Unimatic1140 has asked for the wisdom of the Perl Monks concerning the following question:

Hello World, I've written an extensive Discussion Group CGI in Perl for our web site and it’s been working great for over six months. I've wanted to expand my reporting on our users so I thought it would be good to record their IP address and Browser type when they log in. The Browser type is recording perfectly, but for some reason everyone seems to have the same IP address and I know that can’t be true. While I won’t print the entire Log-In Perl Code here, I will just included the sections that pertain to the recording of the IP and Browser info…
#!/usr/local/bin/perl -- use CGI::Carp qw(fatalsToBrowser); $|=1; $RMIP=$ENV{'REMOTE_ADDR'}; $RUAG=$ENV{'HTTP_USER_AGENT'}; -----(later on in the code)----- # RECORD USERS IP ADDRESSES open (USERIP, ">>/usr/local/www/htdocs/classicappliances/NEW DISCU +SS/PROFILES/USER-IP-FILE.txt"); flock (USERIP, 2); print USERIP "$NAME_CHOICE--REMOTE ADDR-$RMIP---user agent-$RUAG\n +"; close (USERIP); flock (USERIP, 8);
Here is a sample of the results that we’re recorded in my USER-IP-FILE.txt file…
Unimatic1140--REMOTE ADDR-216.23.15.143---remote host----user agent-Mo +zilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90) spambdamn--REMOTE ADDR-216.23.15.143---remote host----user agent-Mozil +la/4.75 [en] (Windows NT 5.0; U) jasonl--REMOTE ADDR-216.23.15.143---remote host----user agent-Mozilla/ +4.0 (compatible; MSIE 5.0; Windows 98; DigExt) earthling177--REMOTE ADDR-216.23.15.143---remote host----user agent-Mo +zilla/4.0 (compatible; MSIE 5.12; Mac_PowerPC) angus--REMOTE ADDR-216.23.15.143---remote host----user agent-Mozilla/4 +.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; MSN 6.1; MSNbMSFT; + MSNmen-us; MSNc11) whirlpoolbklyn--REMOTE ADDR-216.23.15.143---remote host----user agent- +Mozilla/4.0 (compatible; MSIE 5.5; AOL 6.0; Windows 95) trainguy--REMOTE ADDR-216.23.15.143---remote host----user agent-Mozill +a/4.0 (compatible; MSIE 5.5; AOL 6.0; Windows 98; Win 9x 4.90)
See, all the IP address are the same? I thought the $ENV{'REMOTE_ADDR'} command picks up the each users individual IP address? Does anyone see what I’m doing wrong??? Any advice will be greatly appreciated.

Replies are listed 'Best First'.
Re: IP Address of Person Submitting Log-In Request
by Fastolfe (Vicar) on Nov 08, 2001 at 00:48 UTC

    Note that if this is a configuration where you're behind an HTTP proxy, the HTTP proxy will be in the REMOTE_ADDR variable, though some proxies will include an additional client header X-Forwarded-For that contains the IP address of the client of the proxy. So, changing your code to

    $RMIP=$ENV{'HTTP_X_FORWARDED_FOR'} || $ENV{'REMOTE_ADDR'};

    may allow you to gleam the information about the true client in most situations. It depends on the proxy.

    Of course, this is assuming that your traffic is in fact originating from a proxy and there isn't another explanation for the behavior you're seeing.

      If there are additional hops between your server and the client, $ENV{'HTTP_X_FORWARDED_FOR'} will contain their IP address comma-separated, and the first one will be the client address.

      --
      tune

        Thanks for your recommendations Fastolfe and Tune of using $ENV{'HTTP_X_FORWARDED_FOR'} unfortunately this turned up to be a blank too. So I decided to try to record all the current environment variables when ever a user logs into to our web site. Here is a typical expample of what I received for each login:
        User: Appnut SERVER_SOFTWARE is set to Apache/1.3.12 (Unix) PHP/4.0.3pl1 GATEWAY_INTERFACE is set to CGI/1.1 DOCUMENT_ROOT is set to /usr/local/www/htdocs/classicappliances REMOTE_ADDR is set to 216.23.15.143 REQUEST_METHOD is set to POST QUERY_STRING is set to HTTP_ACCEPT is set to application/vnd.ms-excel, application/msword, ap +plication/vnd.ms-powerpoint, image/gif, image/x-xbitmap, image/jpeg, +image/pjpeg, */* REMOTE_PORT is set to 46795 SERVER_ADDR is set to 216.23.15.143 HTTP_ACCEPT_LANGUAGE is set to en-us HTTP_ACCEPT_ENCODING is set to gzip, deflate SCRIPT_FILENAME is set to /usr/local/www/htdocs/classicappliances/cgi- +bin/userlogin.cgi SERVER_NAME is set to classicappliances.com HTTP_PRAGMA is set to no-cache SERVER_PORT is set to 80 PATH_TRANSLATED is set to /usr/local/www/htdocs/classicappliances/cgi- +bin SERVER_ADMIN is set to [no address given] SCRIPT_URI is set to http://classicappliances.com/cgi-bin/cgiwrap/clas +sicappliances/userlogin.cgi SCRIPT_URL is set to /cgi-bin/cgiwrap/classicappliances/userlogin.cgi SERVER_SIGNATURE is set to <ADDRESS>Apache/1.3.12 Server at classicapp +liances.com Port 80</ADDRESS> SERVER_PROTOCOL is set to HTTP/1.0 HTTP_REFERER is set to http://classicappliances.com/NEW%20DISCUSS/DISP +LAY%20PAGES/NEW%20DISCUSS%20LOGIN.htm HTTP_USER_AGENT is set to Mozilla/4.0 (compatible; MSIE 5.01; Windows +95) PATH is set to /usr/local/sbin:/sbin:/usr/sbin:/usr/local/bin:/usr/bin +:/usr/ucb:/usr/ccs/bin:/usr/openwin/bin:/usr/local/scripts:/usr/local +/www/bin:/shared/var/common:. TZ is set to US/Pacific SCRIPT_NAME is set to /cgi-bin/cgiwrap/classicappliances/userlogin.cgi REQUEST_URI is set to /cgi-bin/cgiwrap/classicappliances/userlogin.cgi PATH_INFO is set to CONTENT_LENGTH is set to 51 CONTENT_TYPE is set to application/x-www-form-urlencoded HTTP_FORWARDED is set to by http://uspxy16.fa.aexp.com:8080 (Netscape- +Proxy/3.53) HTTP_HOST is set to www.classicappliances.com
        I tried to contact the technical support of my ISP and they said "sorry, but we don't provide tech support for CGI programming". So I'm still stuck, any other ideas out there? Thanks again for everyone's suggestions
Re: IP Address of Person Submitting Log-In Request
by Rex(Wrecks) (Curate) on Nov 07, 2001 at 22:53 UTC
    Is your web server being NAT'ed? firewalled? proxied? There are a bunch of network devices that can do funky things with incoming traffic and headers.

    Also, what does the code that is recording the IP addresses look like? Where are you getting the addresses from? If whatever you are doing is grabbing the wrong part of the header you might be getting the last routers IP addr as the source, in which case it will be the same almost every time (only a couple unlikely scenario's I can think of where it would be more than 1)

    There are alot of things that could be happening here, and without a little more topo info, as well as info on where this log entry is coming from, it's quite hard to say what is going on.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
      Hi Rex, thanks for your response. The part of the code that is recording the IP address and browser is simply:
      #!/usr/local/bin/perl -- use CGI::Carp qw(fatalsToBrowser); $|=1; $RMIP=$ENV{'REMOTE_ADDR'}; $RUAG=$ENV{'HTTP_USER_AGENT'};
      Later on into the code, those two simple variables go on to be recorded into a text file for later viewing at my convenience.
Re: IP Address of Person Submitting Log-In Request
by kwoff (Friar) on Nov 07, 2001 at 22:31 UTC
    Maybe you have a layer between you and the user, like a load balancer.
    216.23.15.143 == web08.hispeed.net
    What does your access_log say? Ask your sysadmin perhaps.