Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Default how to get the host name

    hi all,

    i have a apache server running in remote place. I have a project that in running in this server. what is my requirement is that i want to get the host-name or ipaddress of the user who logs into this project and store it in the database. i have a simple code that returns the hostname, but it is returning the hostname of the server where this project is running. please help me on this.

    regards,
    shreeharsha

  2. #2
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    Is this project of yours is running on what component, JApplet or JFrame?
    If JApplet, is this running on a web host?
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

  3. #3
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Default how to get the host name

    hi,
    its simple jsp-servlet project.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default

    I'd have a look in the request header.
    I think the IP is in there somewhere (can't guarantee it since I've not had to get that data before).

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default

    Damn...I was only looking at the HttpServletRequest specific methods!

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Actually if the client behind a proxy then you may not get the really IP. Then you'll get the proxy IP.
    Last edited by Eranga; 10-07-2010 at 12:12 PM. Reason: added more

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default

    Well yes, but that's life.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Of course. But still it's possible to bypass that, ;) only if proxy included client IP in HTTP header, which is normally wont do with proxy.

    Java Code:
    <%
    out.print( request.getHeader("x-forwarded-for") );
    %>
    Note: Please check spellings.


Similar Threads

  1. How to create file into another host from a host
    By varadha in forum Networking
    Replies: 3
    Last Post: 02-10-2010, 09:03 PM
  2. copy file from local host to remote host
    By isotoper in forum New To Java
    Replies: 4
    Last Post: 12-24-2009, 04:41 PM
  3. Host Blacklisted
    By neeti in forum Networking
    Replies: 6
    Last Post: 10-27-2009, 10:31 AM
  4. Replies: 0
    Last Post: 10-31-2008, 07:07 PM
  5. Getting host name/address
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-19-2007, 04:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •