Share on Google+Share on Google+

Get IP Address Example

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.

import java.util.*;

public class IpAddress {

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

  Enumeration<NetworkInterface> nets = 

  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);

Display name : MS TCP Loopback interface
InetAddress : /

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

Download code


Posted on: October 23, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Get IP Address Example  

Post your Comment

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