• Post Reply Bookmark Topic Watch Topic
  • New Topic

client machine name ip address

 
kiran nyala
Ranch Hand
Posts: 55
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
i am trying to get the ip address of client machine and also its name. I found to get IP address but not the name of it when running on tomcat server. Following the code i tried



out put: this out put for the request made from the system in which the server is running (i.e., local host)

remote adress::0:0:0:0:0:0:0:1
inet address::0:0:0:0:0:0:0:1
comp name::KIHYDD0818



out put: this is out put for remote system request

remote adress::172.20.129.39
inet address::172.20.129.39
comp name::KIHYDD0818


see clearly i am able to get the ip address of remote system i.e., 172.20.129.39 but the name is same as local host. Here i think will always return the name of local host. but i need the name of remote system. please suggest me
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two points:

1) Your code explicitly calls "getLocalHost()" - is it really surprising that you're getting the name of localhost? Note that that is a static method of InetAddress; what do the javadocs say it does?

2) Be aware that many (or most) machines will have not a name that can be looked up in this way. What you need to do is to perform a DNS lookup of that IP address's A record. The DNSJava library can do that pretty easily.
 
kiran nyala
Ranch Hand
Posts: 55
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, i also tried servlet request methods




output
ip address::172.20.129.39
name::172.20.129.39

according to API request.getRemoteHost() should return qualified name of remote system, but i am still getting IP address for this statement. Can't we get the name of remote system.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do the javadocs of the getRemoteHost method have to say about that? They certainly don't say that it will always return a machine name.

But to me it doesn't look like 172.20.129.39 has a DNS A record, at least not a public one. Does it have a private A record in your network's DNS server? Most machines won't have that, though. And InetAddress knows nothing about remote machine names that aren't part of DNS, just in case that's what you were hoping for.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!