Filtering JSP page based on client IP

Discussion in 'Java' started by Mich, Jan 9, 2007.

  1. Mich

    Mich Guest

    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!
     
    Mich, Jan 9, 2007
    #1
    1. Advertising

  2. Mich

    Mich Guest

    "Mich" <> wrote in message
    news:YQSoh.71025$...
    > 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.
     
    Mich, Jan 9, 2007
    #2
    1. Advertising

  3. Mich

    Lew Guest

    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
     
    Lew, Jan 10, 2007
    #3
  4. 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.
     
    Andrew Thompson, Jan 10, 2007
    #4
  5. Mich

    Nigel Wade Guest

    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 :
    Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
     
    Nigel Wade, Jan 10, 2007
    #5
  6. Mich

    bjeremy Guest

    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...
     
    bjeremy, Jan 10, 2007
    #6
  7. 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
     
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Jan 11, 2007
    #7
  8. Mich

    Mich Guest

    "Lew" <> wrote in message
    news:...
    > 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...
     
    Mich, Jan 11, 2007
    #8
  9. 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.
     
    Andrew Thompson, Jan 11, 2007
    #9
  10. Mich

    Lew Guest

    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
     
    Lew, Jan 11, 2007
    #10
  11. Mich

    Mich Guest

    "Andrew Thompson" <> wrote in message
    news:...
    > 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.



    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.
     
    Mich, Jan 11, 2007
    #11
  12. Mich wrote:
    > "Andrew Thompson" <> wrote in message

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

    .....
    > 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.
     
    Andrew Thompson, Jan 11, 2007
    #12
  13. Mich

    Mich Guest

    "Andrew Thompson" <> wrote in message
    news:...
    > Mich wrote:
    >> "Andrew Thompson" <> wrote in message

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

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


    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
    ....
     
    Mich, Jan 11, 2007
    #13
  14. Mich

    Mich Guest

    "Lew" <> wrote in message
    news:...
    > 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?



    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!!)
     
    Mich, Jan 11, 2007
    #14
  15. Mich

    Mich Guest

    "bjeremy" <> wrote in message
    news:...
    >
    > 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...


    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.
     
    Mich, Jan 11, 2007
    #15
  16. Mich

    Chris Uppal Guest

    Mich wrote:

    > 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
     
    Chris Uppal, Jan 11, 2007
    #16
  17. Mich

    bjeremy Guest

    Mich wrote:
    > "Andrew Thompson" <> wrote in message
    > news:...
    > > 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.

    >
    >
    > 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....
     
    bjeremy, Jan 11, 2007
    #17
  18. Mich

    Mich Guest

    "Chris Uppal" <-THIS.org> wrote in message
    news:45a6a3ff$1$757$...
    > Mich wrote:
    >
    >> 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 ?



    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.
     
    Mich, Jan 11, 2007
    #18
  19. Mich

    Mich Guest

    "bjeremy" <> wrote in message
    news:...
    >
    > Mich wrote:
    >> "Andrew Thompson" <> wrote in message
    >> news:...
    >> > 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.

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


    .... 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.
     
    Mich, Jan 11, 2007
    #19
    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. RogerTBrick
    Replies:
    2
    Views:
    405
    RogerTBrick
    Mar 4, 2005
  2. Replies:
    4
    Views:
    15,433
  3. sp
    Replies:
    2
    Views:
    846
  4. Replies:
    0
    Views:
    4,403
  5. Sjaakie
    Replies:
    10
    Views:
    752
    Nick Gilbert
    Sep 21, 2006
Loading...

Share This Page