0

i would like to know how to get ipaddress using host name of my friends computer in java programming. I have tried using getByName(".....") method ,but it is a failure. will u assist me.......

4
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by Ezzaral
0

Hmm, the InetAddress.getByName(String) method should work. Are you using the full computer name? That is, including the network?

0

Hmm, the InetAddress.getByName(String) method should work. Are you using the full computer name? That is, including the network?

i don't know weather it is involved in a network or not. how i should know wheather it is involved in a network or not.

0

What I think is your friend either doesn't want you to have his IP address or doesn't know you are trying to get it. I also think it would be beneficial to those trying to help you if you showed them what you have done, i.e some code.

0

What I think is your friend either doesn't want you to have his IP address or doesn't know you are trying to get it. I also think it would be beneficial to those trying to help you if you showed them what you have done, i.e some code.

import java.net.*;
import java.util.*;
public class InternetAddress
{
	public static void main(String args[])
	{
		try
		{
			InetAddress localaddr = InetAddress.getByName("<name of my friends computer>");
			
			System.out.println ("Local IP Address : " + localaddr );
			System.out.println ("Local hostname   : " + localaddr.getHostName());
		}
		catch (UnknownHostException e)
		{
			System.err.println ("Can't detect localhost : " + e);
		}
		
	}
}
0

The only time that the getByName method hasn't worked for me was when I was trying to access a computer on a different domain / network to me. I had to use the fully qualified computer name for it to work. What is the name you are inserting and are you on the same domain?

1

i don't know weather it is involved in a network or not. how i should know wheather it is involved in a network or not.

If he's not on a network, how do you figure he's going to have an IP address? Do you know what an IP address is for?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.