IP address, how?

Discussion in 'Perl Misc' started by warpman, Mar 18, 2005.

  1. warpman

    warpman Guest

    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.
     
    warpman, Mar 18, 2005
    #1
    1. Advertising

  2. warpman

    Keith Keller Guest

    On 2005-03-18, 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?


    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

    --
    -francisco.ca.us
    (try just my userid to email me)
    AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
    see X- headers for PGP signature information
     
    Keith Keller, Mar 18, 2005
    #2
    1. Advertising

  3. 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...

    warpman wrote:

    > 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--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Mar 18, 2005
    #3
  4. warpman

    Eric Bohlman Guest

    "warpman" <> wrote in news:1111170260.053444.22820
    @f14g2000cwb.googlegroups.com:

    > 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.
     
    Eric Bohlman, Mar 18, 2005
    #4
  5. warpman

    Brian Wakem Guest

    Sherm Pendley wrote:

    > 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...
    >
    > warpman wrote:
    >
    >> 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 which case $ENV{'HTTP_X_FORWARDED_FOR'} can sometimes be useful.


    --
    Brian Wakem
     
    Brian Wakem, Mar 18, 2005
    #5
  6. warpman

    Tintin Guest

    "warpman" <> wrote in message
    news:...
    > 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.
     
    Tintin, Mar 19, 2005
    #6
  7. On Sat, 19 Mar 2005, Tintin wrote:

    > [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.
     
    Alan J. Flavell, Mar 19, 2005
    #7
  8. 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.

    gtoomey
     
    Gregory Toomey, Mar 20, 2005
    #8
  9. warpman

    Peter Wyzl Guest

    "Gregory Toomey" <> wrote in message
    news:...
    : 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
     
    Peter Wyzl, Mar 20, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. avnrao
    Replies:
    1
    Views:
    7,232
    avnrao
    May 4, 2004
  2. Patrice
    Replies:
    0
    Views:
    890
    Patrice
    May 4, 2004
  3. Raterus
    Replies:
    0
    Views:
    439
    Raterus
    Jun 2, 2004
  4. Alex Stevens
    Replies:
    0
    Views:
    781
    Alex Stevens
    Aug 10, 2004
  5. =?Utf-8?B?QW5nZWw=?=

    Pass a Web Address and return a File System Address

    =?Utf-8?B?QW5nZWw=?=, Sep 20, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    541
    =?Utf-8?B?U3RldmUgQy4gT3Jy?=
    Sep 21, 2005
Loading...

Share This Page