I am trying to retrieve the environment variables from a CGI script after it has been submitted, however, the only environment variables I am able to retrieve are REMOTE_HOST, REMOTE_ADDR, and REQUEST_METHOD. To obtain these I use:
$ip_addr = $ENV{'REMOTE_ADDR'}; $host_name = gethostbyaddr(inet_aton($ip_addr), AF_INET); $req_method = $ENV{'REQUEST_METHOD'};
The other variabels I wish to obtain, but do not show up are as follows:
$host_port = $ENV{'REMOTE_PORT'}; $user_agent = $ENV{'HTTP_USER_AGENT'}; $mac_address = `/sbin/arp -a $ip_addr` =~ /at\s+(\S+)\s+/; $user_referer = $ENV{'HTTP_REFERER'};
I know I can get all of the variables by doing the following:
#!/usr/bin/perl print "Content-type: text/html\n\n"; $n = 0; print "<tt>\n"; foreach $key(sort keys(%ENV)) { print "$key = $ENV{$key}<p>"; @keys[$n] = $ENV{$key}; $n++; } print qq~The remort port is $keys[15]~;
But that seems a little longwinded and unnecessary. If anyone could suggest something shorter or possibly point out what I'm doing wrong that would be great. Thank again!

In reply to HTTP/CGI Environmnet Variables by intranetman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.