Client Machine Name or Host name ?

Discussion in 'Java' started by Anil G, Jan 9, 2004.

  1. Anil G

    Anil G Guest

    Hi,

    Is it possible to retrieve client's computer name or Host name instead of just IP?

    Currently i am using following,

    String remoteAddress = request.getRemoteAddr();
    String remoteHost = request.getRemoteHost();
    String remoteUser = request.getRemoteUser();


    But this yeilds only IP Addresses and remoteUser as null.

    Please advise,

    Thanks,

    Anil G
     
    Anil G, Jan 9, 2004
    #1
    1. Advertising

  2. Anil G

    Ryan Stewart Guest

    "Anil G" <> wrote in message
    news:...
    > Hi,
    >
    > Is it possible to retrieve client's computer name or Host name instead of

    just IP?
    >
    > Currently i am using following,
    >
    > String remoteAddress = request.getRemoteAddr();
    > String remoteHost = request.getRemoteHost();
    > String remoteUser = request.getRemoteUser();
    >
    >
    > But this yeilds only IP Addresses and remoteUser as null.
    >
    > Please advise,
    >
    > Thanks,
    >
    > Anil G


    I assume you're talking HttpServletRequest here. Read your API's:
    getRemoteAddr--Returns the Internet Protocol (IP) address of the client or
    last proxy that sent the request.
    getRemoteHost--Returns the fully qualified name of the client or the last
    proxy that sent the request. If the engine cannot or chooses not to resolve
    the hostname (to improve performance), this method returns the dotted-string
    form of the IP address.
    getRemoteUser--Returns the login of the user making this request, if the
    user has been authenticated, or null if the user has not been authenticated.

    So first notice that getRemoteAddr and getRemoteHost both may not get the
    client's machine. If the request came through a proxy, it will get that.
    Second, if getRemoteHost is giving an IP, it may not be able to get a host
    name. Third, you can't get a user name if the server from which the request
    is coming does not require login. That said, if you have an IP address, you
    can attempt to get a host name like this:
    String ip = "127.0.0.1";
    String hostName = InetAddress.getByName(ip).getHostName(); // or
    ..getCanonicalHostName()

    See http://java.sun.com/j2se/1.4.1/docs/api/java/net/InetAddress.html for
    more info on getHostName and such.
     
    Ryan Stewart, Jan 9, 2004
    #2
    1. Advertising

  3. Anil G <> wrote:
    : Is it possible to retrieve client's computer name or Host name instead of just IP?

    : Currently i am using following,

    : String remoteAddress = request.getRemoteAddr();
    : String remoteHost = request.getRemoteHost();
    : String remoteUser = request.getRemoteUser();


    : But this yeilds only IP Addresses and remoteUser as null.

    I will assume that you talk about servlets or something similar here
    (my guess is that request is a HttpServletRequest, should not matter
    much).

    Do the client support reverse DNS lookups? probably not and then it is
    hard to do it. Also not that an IP sometimes maps to several
    names. Some of the web host companies run a few thousand host names on
    a single ip-address.

    Why do you need the name of the computer?

    If you want remoteUser to be set you have to ask the client to
    authenticate itself. Read rfc 2616, 2617 for basic authentication. If
    you run tomcat you can configure authentication against text
    file/db/ldap, but you will have to read the tomcat manual to see how.

    /robo
     
    Robert Olofsson, Jan 9, 2004
    #3
  4. Anil G

    johnGC

    Joined:
    Nov 13, 2006
    Messages:
    1
    johnGC, Nov 13, 2006
    #4
  5. Anil G

    v_parthi

    Joined:
    Jan 31, 2008
    Messages:
    1
    (1) Go to.... <apache-directory>/conf/server.xml

    (2) Locate the following part:

    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 has been changed to apache's port 80 -->
    <Connector port="8080" maxHttpHeaderSize="8192"
    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" redirectPort="8443" acceptCount="100"
    connectionTimeout="20000" disableUploadTimeout="true" />

    (3) Change enableLookups="true"

    (4) Now, restart tomcat and reload the jsp containing getRemoteHost() method! Hope you should see the host name now. It may not work through proxy, so you can override proxy for local addresses.
     
    v_parthi, Jan 31, 2008
    #5
    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. Joey
    Replies:
    0
    Views:
    372
  2. Orpheus66
    Replies:
    0
    Views:
    4,537
    Orpheus66
    Jul 30, 2003
  3. Jerry Qu
    Replies:
    1
    Views:
    533
    lee atkinson
    Feb 20, 2009
  4. Dan Stromberg
    Replies:
    0
    Views:
    489
    Dan Stromberg
    Dec 23, 2010
  5. Kanth
    Replies:
    0
    Views:
    166
    Kanth
    Jan 22, 2008
Loading...

Share This Page