Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

SOAP::Lite - Finding callers IP

by Biker (Priest)
on Jan 23, 2003 at 13:53 UTC ( #229307=perlquestion: print w/replies, xml ) Need Help??

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

I'm playing around with SOAP::Lite as a CGI script.

My little CGI test script works fine, but I'm looking for a way to find out the IP address of the caller of the script. (I believe the IP address technically can be spoofed, but this is to be executed in a fairly trusted environment.)

It would be useful when logging unexpected input parameter contents to the CGI script and also (potentially) for statistics purposes.

I haven't found any hints in the docs I've read so far.

Any hints?

Everything went worng, just as foreseen.

Replies are listed 'Best First'.
Re: SOAP::Lite - Finding callers IP
by valdez (Monsignor) on Jan 23, 2003 at 14:03 UTC

    If you are using Apache, look into the %ENV variable; there you will find REMOTE_ADDR and other useful informations.

    Ciao, Valerio :
      print "Content-type: text/html\n\n"; print "<HTML> <HEAD><TITLE>Env</TITLE></HEAD> <BODY><TABLE>\n"; while (my ($k, $v) = each %ENV) { print "<TR><TD>$k</TD><TD> = $v</TD></TR>\n"; } print "</TABLE></BODY></HTML>";

      Jaap Karssenberg || Pardus (Larus)? <>
      >>>> Zoidberg: So many memories, so many strange fluids gushing out of patients' bodies.... <<<<

      I do use Apache, but I must keep my CGI script compatible between Apache and IIS V5. (Company policies.)

      And yes, I can find REMOTE_ADDR => in both environments.

      Great. Thanks a lot.

      Everything went worng, just as foreseen.

Re: SOAP::Lite - Finding callers IP
by foxops (Monk) on Jan 23, 2003 at 14:36 UTC
    How 'bout some inspiration.
    Please forgive all the forward slashing, I've got a hacked-up version of Perl <shrug>
    #!c:/Perl/bin/Perl.exe ## ## printenv -- demo CGI program which just prints its environment ## print "Content-type: text/plain\n\n"; print "\<HTML\>\n"; print "\<HEAD\>\n"; print " \<TITLE\>Testies, Testies, 1-2-3\<\/TITLE\>\n"; print "\<\/HEAD\>\n"; print "\<BODY BGCOLOR\=\"\#c0c0c0\" TEXT\=\"\#000000\" LINK\=\"\#ff000 +0\" VLINK\=\"\#0F0000\"\>\n"; foreach $var (sort(keys(%ENV))) { $val = $ENV{$var}; $val =~ s|\n|\\n|g; $val =~ s|"|\\"|g; print "${var}=\"${val}\"\n"; } print "\<\/BODY\>\<\/HTML\>\n";

    Update:foxops shakes fist at Pardus
      Ugghh! Printing HTML like that, while good at getting stuff done farily quickly, is not recommended for those who wish to learn and grow. How about this instead:
      use strict; use warnings; use CGI qw(:standard); print header, start_html( -title => 'Testing 1-2-3', -bgcolor => '#c0c0c0', ), ul(li[map qq|$_ => "$ENV{$_}"|,keys %ENV]), end_html, ;
      Or this:
      use strict; use warnings; use CGI qw(header); use HTML::Template; my $tmpl = HTML::Template->new(filehandle => \*DATA); $tmpl->param(env => [ map {{ key => $_, val => $ENV{$_}, }} keys %ENV ]); print header, $tmpl->output; __DATA__ <html> <head> <title>Testing 1-2-3</title> </head> <body bgcolor="#c0c0c0"> <ul> <tmpl_loop env> <li><tmpl_var key> = "<tmpl_var name="val" escape="HTML">" </tmpl_loop> </ul> </body> </html>
      And ... if you still insist on printing out HTML like you did, then at least check out the q and qq operators:
      # look ma, no slashes! print qq|${var} = "${val}"\n|; print q|<body bgcolor="#c0c0c0">\n|;


      (the triplet paradiddle with high-hat)

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2023-11-29 16:10 GMT
Find Nodes?
    Voting Booth?

    No recent polls found