• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

client machine name ip address

 
Ranch Hand
Posts: 57
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 57
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It was the best of times. It was the worst of times. It was a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic