IP address, how?

W

warpman

I'm new to perl and need some help. I currently have a guestbook that
when a user posts a message I get the following information.

You have a new entry in your guestbook:
message text area...
city, st country - date and time

My question is how do I get the IP address from the person posting the
message sent to me? Why the IP? Well, because lately I've been getting
a lot of spam on the guestbook. Any help or information would be
appreciated.
 
K

Keith Keller

I'm new to perl and need some help. I currently have a guestbook that
when a user posts a message I get the following information.

You have a new entry in your guestbook:
message text area...
city, st country - date and time

My question is how do I get the IP address from the person posting the
message sent to me?

Assuming you're trying to detect the IP from a CGI script on a
webserver, look at the remote_host call in CGI.pm.

--keith
 
S

Sherm Pendley

Your question is off-topic for a Perl group. It has nothing to do with Perl.
That is, the answer would have been the same if you were writing your CGI
in Python, C, or any other language. It would have been better to post it
to a CGI group such as comp.infosystems.www.authoring.cgi. Having said
that...
My question is how do I get the IP address from the person posting the
message sent to me?

It's in the REMOTE_ADDR environment variable. It's not very reliable though
- it can be the address of a proxy, for example.

In Perl, environment variables are in %ENV, so you could read it like this:

my $ip = $ENV{'REMOTE_ADDR'};

sherm--
 
E

Eric Bohlman

I'm new to perl and need some help. I currently have a guestbook that
when a user posts a message I get the following information.

You have a new entry in your guestbook:
message text area...
city, st country - date and time

My question is how do I get the IP address from the person posting the
message sent to me? Why the IP? Well, because lately I've been getting
a lot of spam on the guestbook. Any help or information would be
appreciated.

You get it from the request headers. If you're using CGI.pm, then
remote_host() is probably what you want. Otherwise, it's not really a Perl
question since the way of doing it would be the same in any language.
 
B

Brian Wakem

Sherm said:
Your question is off-topic for a Perl group. It has nothing to do with
Perl. That is, the answer would have been the same if you were writing
your CGI in Python, C, or any other language. It would have been better to
post it to a CGI group such as comp.infosystems.www.authoring.cgi. Having
said that...


It's in the REMOTE_ADDR environment variable. It's not very reliable
though - it can be the address of a proxy, for example.


In which case $ENV{'HTTP_X_FORWARDED_FOR'} can sometimes be useful.
 
T

Tintin

warpman said:
I'm new to perl and need some help. I currently have a guestbook that
when a user posts a message I get the following information.

You have a new entry in your guestbook:
message text area...
city, st country - date and time

My question is how do I get the IP address from the person posting the
message sent to me? Why the IP? Well, because lately I've been getting
a lot of spam on the guestbook. Any help or information would be
appreciated.

[OT Answer]

The IP address of the poster should be in your web server logs.
 
A

Alan J. Flavell

[OT Answer]

OT answers have a tendency to be misleading...
The IP address of the poster should be in your web server logs.

Anyone seriously contemplating mischief would surely find themselves
an HTTP proxy to hide behind. So the IP address in the server log is
quite likely to belong to some insecure proxy. "Preferably" one that
does not pass along the address of the real client.

More comprehensive answers can be found where this issue is on-topic,
I'm sure.
 
G

Gregory Toomey

warpman said:
I'm new to perl and need some help. I currently have a guestbook that
when a user posts a message I get the following information.

You have a new entry in your guestbook:
message text area...
city, st country - date and time

My question is how do I get the IP address from the person posting the
message sent to me? Why the IP? Well, because lately I've been getting
a lot of spam on the guestbook. Any help or information would be
appreciated.

If you use Apache its passed as an environment variable.

gtoomey
 
P

Peter Wyzl

: warpman wrote:
:
: > I'm new to perl and need some help. I currently have a guestbook that
: > when a user posts a message I get the following information.
: >
: > You have a new entry in your guestbook:
: > message text area...
: > city, st country - date and time
: >
: > My question is how do I get the IP address from the person posting the
: > message sent to me? Why the IP? Well, because lately I've been getting
: > a lot of spam on the guestbook. Any help or information would be
: > appreciated.
:
: If you use Apache its passed as an environment variable.

It's passed as an environment variable whether you use Apache or not...

P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top