Get System Ip

The System IP address is a unique numerical identification assigned to a different system involved in the network for communication.

Get System Ip

The System IP address is a unique numerical identification assigned to a different system involved in the network for communication.

Get System Ip

Get System Ip

     

The System IP address is a unique numerical identification assigned to a different system involved in the network for communication. The Format for a IP address is a 32- bit numeric address written as four number separated by periods i.e 192.168.1.1 is an example of IP address. Two IP address cannot be same as it would rise to IP conflict in a System.

Understand with Example

In this Tutorial we want to describe you a code that helps you in understanding to get a IP address. For this we have a class name GetSystemIP,Inside the main method we have a class NetworkInterface,this class represents a Network Interface made up of a name and a list of IP addresses assigned to this interface. This is used to identify the list of multicast group joined  to identify the local interface.

1)getNetworkInterface( )  -  This method returns you the interface used on this machine.

The System.outprintln print the interface name by calling the get Display Name ( ) method.

2)getDisplayName ( )   -  This method returns you name of the network interface.

3)getInet Addresses( )  - This  method returns you Enumeration with  all the  subset of the Inet addresses bound to this network interface.

4)get Host Name( )   - This method returns you the information about the hostname for the current machine.

5)get Host Address( )  -This method return you the address of the host.

The inet Address class provides you the IP address of the current system.

GetSystemIp.java

import java.net.*;
import java.util.*;

public class GetSystemIP {

 public static void main(String args[]) throws Exception {

  Enumeration<NetworkInterface> nets = 
 NetworkInterface.getNetworkInterfaces();


  for (NetworkInterface netint : Collections.list(nets)) {
 System.out.println("\nInterface Name : " + netint.getDisplayName());

  Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();

 for (InetAddress inetAddress : Collections.list(inetAddresses)) {

 System.out.println("Local host Name\t: " + inetAddress.getHostName());
 System.out.println("Host Address\t: " + inetAddress.getHostAddress());
  }

  }
  }
}

Output

Interface name  : MS TCP Loopback interface
Local host name : localhost
Host Address  : /127.0.0.1

Display name  : Intel(R) PRO/100 VE Network Connection - 
  Packet Scheduler Miniport
Local host name : SAM
Host Address  : /
192.168.10.208

Download code