Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Environment Variables

by Legg83 (Novice)
on Aug 17, 2001 at 23:52 UTC ( #105795=perlquestion: print w/replies, xml ) Need Help??

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

Is there someplace, or some way I could find out every CGI Environment variable I can use? Namely, I want to know the persons ip, and the persons dns

Replies are listed 'Best First'.
Re: Environment Variables
by synapse0 (Pilgrim) on Aug 18, 2001 at 00:09 UTC
    You can do a
    print "Content-Type: text/html\n\n"; foreach (keys %ENV) { print "$ENV{$_} <BR>\n"; }
    and see what's available to you.

    update: obviously that was really silly of me to leave off the key in the printed value.. sheesh.. workin in windows makes me stupid. Thanks for correcting that maverick.
      Would also be helpful to see what key has what value :)
      print "Content-Type: text/html\n\n"; foreach (keys %ENV) { print "$_ => $ENV{$_} <BR>\n"; }
      'course Data::Dumper is your friend....
      use Data::Dumper; print "Content-Type: text/plain\n\n"; print Dumper \%ENV;

      perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

        Of course you should remember to remove Data::Dumper afterwards... I'm told it is quite heavy on the processing

        Although I confess I've never used it :)


        Sorry, Apparently its not heavy on processing, just worth removing because of its actual size!!! (1000 lines)
Re (tilly) 1: Environment Variables
by tilly (Archbishop) on Aug 18, 2001 at 20:54 UTC
    In addition to the above scripts, try this one:
    #! /usr/bin/perl use Data::Dumper; $Data::Dumper::Indent = 1; print "Content-Type: text/plain\n\n"; print Data::Dumper->Dump([\%ENV], ['*ENV']);
    It isn't much of an improvement this time (though it will help in the unusual occurance that any environment variables have data in them special to HTML), but it is handy to know about the options that Data::Dumper has for more complex data structures...
Re: Environment Variables
by aquacade (Scribe) on Aug 18, 2001 at 09:25 UTC
    Use remote_addr() function to return the dotted IP address of the remote host.

    Go see the CGI author's website at HTTP Session Variables Be sure to scroll to the top for the full table of contents!

    I'm not sure how to capture DNS info. If you want to look someone up, just use a WHOIS portal like, find the domain's registrar site, and go look them up there.

    ..:::::: aquacade ::::::..

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://105795]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2021-10-19 16:11 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (77 votes). Check out past polls.