Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: All
Sep 1, 1999

Discover the IP Address of Your Local Machine

The class java.net.InetAddress represents an Internet Protocol (IP) address. It has a static method, getLocalHost(), that you can use to obtain an instance of java.net.InetAddress based on your local machine's IP settings.

Then, use the getHostAddress() method of java.net.InetAddress class to obtain the IP address. The following code demonstrates this:

 
try
{
	java.net.InetAddress localMachine =
java.net.InetAddress.getLocalHost();
	System.out.println ("IP of local machine: " +
localMachine.getHostAddress());
}
catch(catch(java.net.UnknownHostException uhe)
{
	//handle exception
}

Behrouz Fallahi
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap