Filtering JSP page based on client IP

M

Mich

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

Mich

Mich said:
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.
 
L

Lew

Mich said:
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
 
A

Andrew Thompson

Mich said:
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.
 
N

Nigel Wade

Mich said:
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.
 
B

bjeremy

Mich said:
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...
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Mich said:
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
 
M

Mich

Lew said:
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...
 
A

Andrew Thompson

Mich said:
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.
 
L

Lew

Nigel said:
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
 
M

Mich

Andrew Thompson said:
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.


In this case it's just a 'problem' with some product descriptions. The
products themselves aren't even sold in Canada, but since the company is
based in Canada a gov official has sent as letter arguing about that. It's
most likely that the gov decision is illegal, but blocking access from
Canada solves the problem.
 
A

Andrew Thompson

Mich said:
.....
In this case it's just a 'problem' with some product descriptions. The
products themselves aren't even sold in Canada, but since the company is
based in Canada a gov official ..
*

...has sent as letter arguing about that. It's
most likely that the gov decision is illegal, but blocking access from
Canada solves the problem.

* gov. officials, riiiIIiight!! You should have said so in
the first place. Only a (nasty, officious, small minded,
power hungry, sediment feeding & scum-sucking)
government official could prompt such a silly situation.

I say go for the 'I am not Canadian' click-thru*, since
I feel it shows the correct level of contempt for such
officialdom (of course, your lawyers may advise
otherwise).

* I think the term for it is 'plausible deniability'. ;-)

Andrew T.
 
M

Mich

Andrew Thompson said:
* gov. officials, riiiIIiight!! You should have said so in
the first place. Only a (nasty, officious, small minded,
power hungry, sediment feeding & scum-sucking)
government official could prompt such a silly situation.

I say go for the 'I am not Canadian' click-thru*, since
I feel it shows the correct level of contempt for such
officialdom (of course, your lawyers may advise
otherwise).

* I think the term for it is 'plausible deniability'. ;-)

Andrew T.

What I am thinking of doing is to post a disclaimer such as "This product
description does not apply to Canadian residents." I will add a link such
as "Canadian Product Description" that will go to a page that explains why
there is no product description. I might even add a link to bring up an
email that will be sent to the government department and perhaps flood them
....
 
M

Mich

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


Good point, and it seems that the whole thing is not very practical ... But
I would think that being able to filter out the vast majority of visists
would be enough (I hope!!)
 
M

Mich

bjeremy said:
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...

Exactly ... but I would think that in my situation being able to block most
connections from Canada would be enough to fulfil the 'legal' requirements.
It would be like a product not being sold in Canada, but that would not
prevent someone from buying it in Vermont and then bringing it into Canada.
 
C

Chris Uppal

Mich said:
Good point, and it seems that the whole thing is not very practical ...
But I would think that being able to filter out the vast majority of
visists would be enough (I hope!!)

Presumably the important point is that you have made a "best effort" to avoid
pressing your nefarious product descriptions upon the unfortunate citizens of
Canada.

I have no idea whether that would satisfy legal requirements as regard your
(potential) dispute with the government, but there is also the issue of your
responsibility to share holders, etc. They might want to reduce the chance of
a dispute with the government in the first place, or their exposure should the
dispute actually occur (and be lost).

BTW, have you sorted out the technical half of your problem -- how to get the
client's IP address ?

-- chris
 
B

bjeremy

Mich said:
In this case it's just a 'problem' with some product descriptions. The
products themselves aren't even sold in Canada, but since the company is
based in Canada a gov official has sent as letter arguing about that. It's
most likely that the gov decision is illegal, but blocking access from
Canada solves the problem.

Ahh... this just proves my conspiracy theory that the Canucks are
keeping all the good hockey skates for themselves, while selling us
Americans the cheap knock-offs....
 
M

Mich

Chris Uppal said:
Presumably the important point is that you have made a "best effort" to
avoid
pressing your nefarious product descriptions upon the unfortunate citizens
of
Canada.

I have no idea whether that would satisfy legal requirements as regard
your
(potential) dispute with the government, but there is also the issue of
your
responsibility to share holders, etc. They might want to reduce the
chance of
a dispute with the government in the first place, or their exposure should
the
dispute actually occur (and be lost).

BTW, have you sorted out the technical half of your problem -- how to get
the
client's IP address ?


I am the only shareholder, so things are ok on that side. I am convinced
that the government position is wrong, and I have sent a polite letter back
to them indicating that since the product is not sold in Canada - its
shipped outside of Canada - the description itself is not subject to
Canadain rules.

For right now I am putting on hold trying to block access to the site, since
I expect that the government will reverse its decision. I have been told
that in the tomcat configuration there are blocking parameters available;
but the site is changing servers, so I will look into that afterwards.
 
M

Mich

bjeremy said:
Ahh... this just proves my conspiracy theory that the Canucks are
keeping all the good hockey skates for themselves, while selling us
Americans the cheap knock-offs....

.... and if you even knew about the maple syrup ...my home province of Quebec
has strict rules about the marketing of maple syrup to "maintain" a stable
price. The results is that because of the high price maple syrup is being
warehoused for years and is spoiled while producers are going out of
business.
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top