Home Java Java-get-example Get IP Example



Get IP Example
Posted on: October 23, 2008 at 12:00 AM
This example shows you ip address of your network interface.

Get IP Example

     

This example shows you ip address of your network interface.

Description of the code :

NetworkInterface.getNetworkInterfaces() : Network Interface class is used for get name, and a list of IP addresses assigned to this interface and getNetworkInterfaces method is used for get the list of all InterfaceAddresses of this network interface.

NetworkInterface.getDisplayName() : getDisplayName method is used for display the name of network interface.

NetworkInterface.getInetAddresses : getInetAddress method is used for display the inetaddress of network interface.

GetIp.java


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

public class GetIp {

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

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

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

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

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

  System.out.println("InetAddress : " + inetAddress);
  }
  }
  }
}

Output:

Display name : MS TCP Loopback interface
InetAddress : /127.0.0.1

Display name : Intel(RPRO/100 VE Network Connection - Packet Scheduler Miniport
InetAddress : /192.168.10.208

Download code

 

Related Tags for Get IP Example:
cinterfacenetworkipintthisaddressshowexampleaddworkexamwssheceinmntnetddnetadaceeshowxaxampsessetwkismpltwssthshofacepleplo


More Tutorials from this section

Ask Questions?    Discuss: Get IP Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.