Home » Java programs

Java program to print the hostname and IP address of Local system



Submitted by BalRam Dixit, on May 19, 2017
Java program to find and print the host name, Ip address of local system. This program will print the IP address and Hostname of the system on which program will be executed.

In this java program, we will learn to get the IP address and Hostname of Local System using some of the methods of java.net.* package.

getHostAddress()
This method returns the IP address (host address of the local system)
getHostName()
This method returns the host name (computer name of the local system)

Consider the program

import java.net.*; 
public class LocalIp 
{ 
	public static void main(String[] args) { 
		try { 
			InetAddress address = InetAddress.getLocalHost();
			System.out.println("IP address: " + address.getHostAddress());
			System.out.println("Host name : " + address.getHostName());  
		} 
		catch (UnknownHostException uhEx) { 
			System.out.println( "Could not find local address!"); 
		} 
	} 
}

Output

IP address: 192.168.10.175
Host name : IncludeHelp_PC





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.