• 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

Can we get Domain Name as we pass IP address ?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Output of this Code :

JOHN-PC/192.168.1.2
google.com/74.125.236.1


Now I want to pass IP address & get the Domain Name or URL ...... which code should i type ?


 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think there's any built-in way to extract the domain name. You'd probably just have to look for patterns matching valid domain name formats.

As for getting "the" URL, no, that's not possible. There is no single URL associated with an IP address. A URL is a completely independent thing that has a host component, but there might be zero, one, or many valid URLs for any given host. You can of course construct one using a common format from the host name or IP address, just by building up the appropriate String, and then test to see if you get a response from that URL. You don't even need the InetAddress for that.
 
Johhn Davis
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Here i am getting my computer name and my computer ip as an output. Now suppose i have an another lappy connected with my lappy through modem and i am intending to get its computer name and its IP address ( which i manually assigned it as 192.168.1.3 ) . What changes i am supposed to do ?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the method is InetAddress.getByName(). Look at the docs to confirm, or to find the right method or right spelling. You give it a host either by name or by IP address, and it returns the corresponding InetAddress. Note that the resulting name/address pairing won't always be what you expect. The "computer name" that you see when you log on to your computer won't necessarily be the same as what is given by whatever service responds to InetAddress's request.

Note that in this context, you have to know either the name (noting that the name by which the computer knows itself may not work) or the address.

If your question is really "How do I find the names and addresses of all the computers on my network?" then I can't help you with that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic