An IP (Internet Protocol) address is a numerical unique identification number which is assigned to the devices participating in the network for communication.
Java example program to get IP address of own system
java get own IP address
An IP (Internet Protocol) address is a numerical unique identification number which is assigned to the devices participating in the network for communication. To get IP address of our own system in a java program we will be using InetAddress class.
In our following example program we are getting system's IP by getting the Host address of the local host.
InetAddress ownIP=InetAddress.getLocalHost(); gets the computer system's local host with IP address. Now we can get the IP address with this object by calling method getHostAddress() on the InetAddress object.
Here is the full example code of GetOwnIP.java as follows:
GetOwnIP.java
import java.util.*;
|
Output:
C:\javaexamples>javac GetOwnIP.java C:\javaexamples>java GetOwnIP IP of my system is := 192.168.10.112 |