CGI-Application-Plugin-RemoteIP

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

        # Remove faux IPv6-prefix.
        $ip =~ s/^::ffff://g;
        ..

    Instead your code and use the simpler expression:

        my $ip = $self->remote_ip();

SECURITY
    The code in this module will successfully understand the
    "X-Forwarded-For" header and trust it.

    Unless you have setup any proxy, or webserver, to scrub this header this
    means the value that is used is at risk of being spoofed, bogus, or
    otherwise malicious.

METHODS
  import
    Add our three public-methods into the caller's namespace:

    remote_ip
            The remote IP of the client.

    is_ipv4 A method to return 1 if the visitor is using IPv4 and 0
            otherwise.

    is_ipv6 A method to return 1 if the visitor is using IPv6 and 0
            otherwise.

  remote_ip
    Return the remote IP of the visitor, whether via the "X-Forwarded-For"
    header or via the standard CGI environmental variable "REMOTE_ADDR".

  is_ipv4
    Determine whether the remote IP address is IPv4.

  is_ipv6
    Determine whether the remote IP address is IPv6.

AUTHOR
    Steve Kemp <steve@steve.org.uk>

lib/CGI/Application/Plugin/RemoteIP.pm  view on Meta::CPAN

=for example begin

    my $ip = $self->remote_ip();

=for example end

=cut

=head1 SECURITY

The code in this module will successfully understand the C<X-Forwarded-For>
header and B<trust> it.

Unless you have setup any proxy, or webserver, to scrub this header this means
the value that is used is at risk of being spoofed, bogus, or otherwise
malicious.

=cut

use strict;
use warnings;

lib/CGI/Application/Plugin/RemoteIP.pm  view on Meta::CPAN

        ## use critic
        *{ $callpkg . '::remote_ip' } = \&remote_ip;
        *{ $callpkg . '::is_ipv6' }   = \&is_ipv6;
        *{ $callpkg . '::is_ipv4' }   = \&is_ipv4;
    }
}


=head2 remote_ip

Return the remote IP of the visitor, whether via the C<X-Forwarded-For> header
or via the standard CGI environmental variable C<REMOTE_ADDR>.

=cut

sub remote_ip
{
    my $cgi_app = shift;

    # X-Forwarded-For header is the first thing we look for.
    my $forwarded = $ENV{ 'HTTP_X_FORWARDED_FOR' } || "";
    if ( length $forwarded )
    {

        # Split in case there are multiple values
        my @vals = split( /[ ,]/, $forwarded );

        if (@vals)
        {



( run in 0.280 second using v1.01-cache-2.11-cpan-26ccb49234f )