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.......

EDIT: Never mind, I hit the wrong button.

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

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.

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.

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);
		}
		
	}
}

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?

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.