Re: [squid-users] Getting Source-IP

From: Jeff Pang <pangj_at_arcor.de>
Date: Fri, 23 Apr 2010 16:07:31 +0800

On Fri, Apr 23, 2010 at 3:58 PM, Andreas Müller <amuelle1_at_gmx.de> wrote:
> Hello,
>
> I know that I can't trust in XFF. What is new for me that the comma is optional and so its more difficult to parse the value.
>

Could use the function like Perl's split to get the last IP no matter
the comma exists or not.

$ perl -le '$ip="12.34.56.78,11.22.33.44,1.2.3.4";$last=(split/,/,$ip)[-1];print
$last'
1.2.3.4

$ perl -le '$ip="12.34.56.78,11.22.33.44";$last=(split/,/,$ip)[-1];print
$last'
11.22.33.44

$ perl -le '$ip="12.34.56.78";$last=(split/,/,$ip)[-1];print $last'
12.34.56.78

-- 
Jeff Pang
http://home.arcor.de/pangj/
Received on Fri Apr 23 2010 - 08:07:38 MDT

This archive was generated by hypermail 2.2.0 : Fri Apr 23 2010 - 12:00:05 MDT