Here you can find the source of getLocalInet4Address()
public static List<InetAddress> getLocalInet4Address()
//package com.java2s; //License from project: Open Source License import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; public class Main { /**//from w w w. ja va 2 s. c o m * @return a list of IPv4 addresses for the all local network cards */ public static List<InetAddress> getLocalInet4Address() { ArrayList<InetAddress> ips = new ArrayList<>(); try { Enumeration<NetworkInterface> netIntf = NetworkInterface.getNetworkInterfaces(); while (netIntf.hasMoreElements()) { Enumeration<InetAddress> addresses = netIntf.nextElement().getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress ip = addresses.nextElement(); if (ip instanceof Inet4Address && ip.isSiteLocalAddress()) ips.add(ip); } } } catch (SocketException e) { e.printStackTrace(); } return ips; } }