Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Client Machine Name or Host name ?

Reply
Thread Tools

Client Machine Name or Host name ?

 
 
Anil G
Guest
Posts: n/a
 
      01-09-2004
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
 
Reply With Quote
 
 
 
 
Ryan Stewart
Guest
Posts: n/a
 
      01-09-2004
"Anil G" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> 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/...etAddress.html for
more info on getHostName and such.


 
Reply With Quote
 
 
 
 
Robert Olofsson
Guest
Posts: n/a
 
      01-09-2004
Anil G <(E-Mail Removed)> 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
 
Reply With Quote
 
johnGC johnGC is offline
Junior Member
Join Date: Nov 2006
Posts: 1
 
      11-13-2006
The solution to this problem can be found here
http://aboutoracle.blogspot.com/2006...eaddr-and.html


Regards
 
Reply With Quote
 
v_parthi v_parthi is offline
Junior Member
Join Date: Jan 2008
Posts: 1
 
      01-31-2008
(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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dane Cook: Great S.N.L. host or GREATEST S.N.L. host? Jojo the 90lb hottie Digital Photography 1 02-14-2007 04:55 AM
Cisco PIX 501 - Port forwarded to an internal host via Static NAT doesn't work from internal host JoelSeph Cisco 9 01-23-2006 03:52 PM
PIX: how to allow 1 host from outside interface to access another host on the inside interface? jonnah Cisco 1 04-21-2004 02:26 PM
request.getHeader("Host") returns wrong host name Orpheus66 Java 0 07-30-2003 02:59 PM



Advertisments