[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Finding (dynamic/static/whatever) current IP address ?



Hi 

The rpogram which is attached displays the IP of the host given on command
line. Replace getByName() with getLocalHost() to get the IP of the
localhost.

HTH

On Mon, Dec 25, 2000 at 09:30:31AM -0800, shantanu_gwl@xxxxxxxxxxxx wrote:
>Hi all,
>Can anyone please guide as how to find the current IP address of my machine programmatically, like WINIPCFG in Win98 ? Any straight-forward way to code this in Java ?
>Any pointer will be of immense help. Thanks in advance.
>Regards,
>Shantanu.

-- 
Anand Biligiri S
----------------
Absence makes the heart forget.
import java.net.*;

class JPing
{
	public static void main(String[] args)
	{
		InetAddress host;
		try
		{
			host = InetAddress.getByName(args[0]);
			
			System.out.println(host.getHostAddress());
			
		}
		catch(UnknownHostException e)
		{
			System.out.println("Invalid Host/Host not reacheable:" + args[0]);
		}
	}
}