Block a IP Address in JSP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • naveenkongati
    New Member
    • Oct 2008
    • 52

    Block a IP Address in JSP

    I have designed a application in JSP. In which i want to block few ip address and display a message to the particular user that you have been banned to view this site.
    Thanks & Regards in Advance
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    Congratulation to your achievement. Do you like to show us the design you have done?
    Maybe we can learn from it if you post it under forum "insights".

    Comment

    • chaarmann
      Recognized Expert Contributor
      • Nov 2007
      • 785

      #3
      What's the problem here? Nothing?
      Ah, I see ...
      Congratulation to your achievement. Do you like to show us the design you have done?
      Maybe we can learn from it if you post it under forum "insights".

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        You can retrieve the client's IP address using the request object.
        For example:
        Code:
        out.print( request.getRemoteAddr() );
        out.print( request.getRemoteHost() );
        Please be aware that there may be more than one user with the same IP address because they could be on the same network.

        -Frinny

        Comment

        • chaarmann
          Recognized Expert Contributor
          • Nov 2007
          • 785

          #5
          Dear Frinny,
          I have done a JSP-page for a customer using these commands once. (To be precise, Not to block the client's IP address, but to write it to a log file only). It turned out that I only got 2 different IP addresses in my log from thousands of requests!!! I figured out that these addresses belonged to the 2 proxy servers of the company!
          That means even if your company has no proxy server, the client may have: his company, his ISP, or one of the global servers in the routing table .That has the effect that if you block one IP-address, you also block thousands of other users.
          So this solution is not usable. As far as I know you can only block a user by providing a username/password login mechanism for everyone and then disabling his account.

          But maybe there is a solution I don't know of to get the sender's IP address (Something like tracert or email-header functionality). Maybe something new with the JDK6 or SSL-connection?
          But even then I would not block longer than 10 minutes. Once the user sees he is blocked he would simply cancel the connection to his internet provider and log on again to get a new IP address automatically. (and some other new poor guy who just happened to log on the same time gets the reused old IP address and is blocked for the rest of the 10 minutes! (which is not good, but better that being blocked for the rest of his life :-))

          So I am eager to see the OP's (Naveenkongati) design he claims to have done.

          Or, Frinny, is there a way to get the client's MAC address (the unique number of his network card) somehow?

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            You are quite right chaarmann. That is why I mentioned that there may be more than one user with the same IP if they're on the same network (or using the same proxy).

            You can't get the MAC address through typical web requests.

            A better approach would be as you suggested, block the user based on their login information (ie: user name and password) as apposed to blocking an IP.

            -Frinny

            Comment

            Working...