aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Can we get Domain Name as we pass IP address ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Can we get Domain Name as we pass IP address ?" Watch "Can we get Domain Name as we pass IP address ?" New topic
Author

Can we get Domain Name as we pass IP address ?

Johhn Davis
Greenhorn

Joined: Sep 20, 2012
Posts: 16

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 ?


Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Sep 20, 2012
Posts: 16

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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can we get Domain Name as we pass IP address ?