Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Filtering JSP page based on client IP

Reply
Thread Tools

Filtering JSP page based on client IP

 
 
Mich
Guest
Posts: n/a
 
      01-09-2007
Because of local content rules I have to make some website pages unavailable
for browsers in Canada. Since I am in Canada and I obviously need to view
those pages I need some code such as


if(IP==canada) {
if(IP!=my IP) {
This page is not available in Canada
}
}


I did a Google search on this and everything I found was about filtering the
complete website; and I would really like to be able to do this for
individual pages.


Any help would be very appreciated!


 
Reply With Quote
 
 
 
 
Mich
Guest
Posts: n/a
 
      01-09-2007

"Mich" <(E-Mail Removed)> wrote in message
news:YQSoh.71025$(E-Mail Removed)...
> Because of local content rules I have to make some website pages
> unavailable for browsers in Canada. Since I am in Canada and I obviously
> need to view those pages I need some code such as
>
>
> if(IP==canada) {
> if(IP!=my IP) {
> This page is not available in Canada
> }
> }
>
>
> I did a Google search on this and everything I found was about filtering
> the complete website; and I would really like to be able to do this for
> individual pages.



I have used <%=request.getRemoteAddr()%> but what I get is the IP address of
the server.


 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      01-10-2007
Mich wrote:
>> Because of local content rules I have to make some website pages
>> unavailable for browsers in Canada. Since I am in Canada and I obviously
>> need to view those pages I need some code such as
>>
>>
>> if(IP==canada) {
>> if(IP!=my IP) {
>> This page is not available in Canada
>> }
>> }
>>
>>
>> I did a Google search on this and everything I found was about filtering
>> the complete website; and I would really like to be able to do this for
>> individual pages.

>
>
> I have used <%=request.getRemoteAddr()%> but what I get is the IP address of
> the server.


Generally it is not reliable to use IP address to determine where the browser
is. Too many times the address recoverable is of some intermediate node
(firewall, "Web Seal" server, ...) or otherwise not the "real" IP address of
the sender. Also, I do not know how to reliably correlate IP address with
national origin - you must be digging deeply into DNS records, eh?

Doesn't that just kill performance?

- Lew
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      01-10-2007
Mich wrote:
> Because of local content rules I have to make some website pages unavailable
> for browsers in Canada. ..


So put a 'I am not in Canada' click-through before
the page and be done with it.

(..Just a thought)

Andrew T.

 
Reply With Quote
 
Nigel Wade
Guest
Posts: n/a
 
      01-10-2007
Mich wrote:

> Because of local content rules I have to make some website pages unavailable
> for browsers in Canada. Since I am in Canada and I obviously need to view
> those pages I need some code such as
>
>


The first thing you need to determine is what you mean by "browsers in Canada".
Do you mean the location of the computer which is executing the code for the
browser, or perhaps a proxy which is downloading your page on behalf of the
browser, or where the browser window is actually being displayed and presumably
where a "user" is located.

Each could be in an entirely different country. So you need to ask yourself if
what you are trying to do is either achievable, or meaningful.

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : http://www.velocityreviews.com/forums/(E-Mail Removed)
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
 
Reply With Quote
 
bjeremy
Guest
Posts: n/a
 
      01-10-2007

Mich wrote:
> Because of local content rules I have to make some website pages unavailable
> for browsers in Canada. Since I am in Canada and I obviously need to view
> those pages I need some code such as
>
>
> if(IP==canada) {
> if(IP!=my IP) {
> This page is not available in Canada
> }
> }
>
>
> I did a Google search on this and everything I found was about filtering the
> complete website; and I would really like to be able to do this for
> individual pages.
>
>
> Any help would be very appreciated!


This rant won't solve your problem, but this kind of stuff needs to be
done at the l4 layer with a Firewall service. It really is unreliable
to try and solve it at an application layer level. Also, just knowing
the IP address really will not help all that much, since I can be
located inb Canada and use a proxy server in Minnesota in order to get
your page in canada...

 
Reply With Quote
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      01-11-2007
Mich wrote:
> Because of local content rules I have to make some website pages unavailable
> for browsers in Canada. Since I am in Canada and I obviously need to view
> those pages I need some code such as
>
> if(IP==canada) {
> if(IP!=my IP) {
> This page is not available in Canada
> }
> }
>
> I did a Google search on this and everything I found was about filtering the
> complete website; and I would really like to be able to do this for
> individual pages.


It is called geofiltering/geolocalisation.

You need some simple code and an IP-to-country
database.

There are a couple of free such databases available and
some commercial solutions.

You should be aware that:
1) those databases are not 100% correct more like 95-99%
2) they need to be constantly updated
3) they can not catch people using a proxy server
in another country than where they are sitting

I have a Java program to load data and a demo
of how to test in a JSP page.

Drop me an email if you want a copy of the code.

Arne
 
Reply With Quote
 
Mich
Guest
Posts: n/a
 
      01-11-2007

"Lew" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). ..
> Mich wrote:
>>> Because of local content rules I have to make some website pages
>>> unavailable for browsers in Canada. Since I am in Canada and I obviously
>>> need to view those pages I need some code such as
>>>
>>>
>>> if(IP==canada) {
>>> if(IP!=my IP) {
>>> This page is not available in Canada
>>> }
>>> }
>>>
>>>
>>> I did a Google search on this and everything I found was about filtering
>>> the complete website; and I would really like to be able to do this for
>>> individual pages.

>>
>>
>> I have used <%=request.getRemoteAddr()%> but what I get is the IP address
>> of the server.

>
> Generally it is not reliable to use IP address to determine where the
> browser is. Too many times the address recoverable is of some intermediate
> node (firewall, "Web Seal" server, ...) or otherwise not the "real" IP
> address of the sender. Also, I do not know how to reliably correlate IP
> address with national origin - you must be digging deeply into DNS
> records, eh?
>
> Doesn't that just kill performance?



Thanks ... and after doing a lot more snooping on my part you are obviously
correct about the browser. But I found some products that convert an IP
address to a country...


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      01-11-2007
Mich wrote:
> Because of local content rules I have to make some website pages unavailable
> for browsers in Canada. ...


As an aside. What content would be *not* allowed
in Canada, but *allowed* in other places?

I never got the impression of the Canadians as being
overly keen on censorship, and thought they were
more permissive than (for e.g.) their neighbours
immediately "south o' the border".

Andrew T.

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      01-11-2007
Mich wrote:
>> Because of local content rules I have to make some website pages unavailable
>> for browsers in Canada. Since I am in Canada and I obviously need to view
>> those pages I need some code such as


Nigel Wade wrote:
> The first thing you need to determine is what you mean by "browsers in Canada".
> Do you mean the location of the computer which is executing the code for the
> browser, or perhaps a proxy which is downloading your page on behalf of the
> browser, or where the browser window is actually being displayed and presumably
> where a "user" is located.
>
> Each could be in an entirely different country. So you need to ask yourself if
> what you are trying to do is either achievable, or meaningful.


What about a cellphone registered to a non-Canadian location but used whilst
in Canada? or vice versa?

- Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
3-tier design; sorting and filtering object-based data Sjaakie ASP .Net 10 09-21-2006 08:42 AM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
XSLT filtering based on attribute value sp XML 2 01-24-2006 05:17 AM
XSLT for filtering XML based on attribute value? elora_c@yahoo.com XML 4 05-19-2005 09:09 PM
Filtering one set of elements based on another RogerTBrick XML 2 03-04-2005 11:39 AM



Advertisments