This is a Java Program to Display the IP Address of the System.
InetAddress class represents an Internet Protocol (IP) address. We use the method named getHostAddress() of this class to get the IP address string in textual presentation.
Here is the source code of the Java Program to Display the IP Address of the System. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
import java.net.InetAddress;
public class IP_Address
{
public static void main(String args[]) throws Exception
{
InetAddress IP = InetAddress.getLocalHost();
System.out.println("IP of my system is := "+IP.getHostAddress());
}
}
Output:
$ javac IP_Address.java $ java IP_Address IP of my system is := 127.0.1.1
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
advertisement
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Apply for Computer Science Internship
- Apply for Java Internship
- Practice BCA MCQs
- Check Java Books
- Practice Information Technology MCQs