CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2002
    Posts
    65

    How to get the IP address in JSP?

    Hi. Could someone tell me how to get the IP address of all clients connected to the server in jsp? Also, I want to know how to get the IP address of my machine in jsp. Please can anyone help me?

  2. #2
    Join Date
    Jan 2002
    Location
    Halifax, NS, Canada
    Posts
    985
    Code:
    // gets the remote IP
    String sIPAddress = request.getRemoteAddr();
    Not sure how to get your local IP.

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163
    InetAddress.getHostAddress() returns the IP address of the local host (oddly enough ).

    All things have savour, though some very small,
    Nay, a box on the eare hath no smell at all...
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  4. #4
    Join Date
    Dec 2002
    Posts
    65
    Hi. I already know the InetAddress.getHostAddress but I wanted to know if there is something specific in jsp to get the local IP address ,e.g, request.something

  5. #5
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163
    I'm not really sure I understand you... are you saying you think there should be another method to return the local IP address besides InetAddress.getHostAddress()?

    If you want request information, I suppose you could call HttpServletRequest.getRequestURL() to get the URL the client used to make the request. This will include the protocol, server name, port number, and server path, but it won't necessarily be the IP address.

    Those whom God wishes to destroy, he first makes mad...
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured