Java Program to Get System IP Address in Windows and Linux Machine
IP Address: An Internet Protocol address is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication.
- io (input-output): This package provides for system input and output through data streams, serialization, and the file system.
- net (network): This package provides the classes for implementing networking applications.
- util (utility): It contains the collection framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes
public Enumeration getInetAddresses()
Return Type: It returns an Enumeration of InetAddress.
public List getInterfaceAddresses()
Return Type: It returns a list of java.net.InterfaceAddress instances.
Below is the implementation of the problem statement:
Display name: eth0 Name: eth0 Display name: lo Name: lo System IP: /127.0.0.1
Output in Windows:
Output in Linux:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.