Home Java Java-get-example Get IP Address Example



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

Get IP Address 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.

IpAddress.java

import java.net.*;
import  "#000000">java.util.*;

public class IpAddress {

  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 Address Example:
cinterfacenetworkipintthisaddressshowexampleaddworkexamwssheceinmntnetddnetadaceeshowxaxampsessetwkismpltwssthshofacepleplo


More Tutorials from this section

Ask Questions?    Discuss: Get IP Address Example  

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.