Here you can find the source of getLocalIpByInterfaceName(String interfaceName)
public static String getLocalIpByInterfaceName(String interfaceName) throws SocketException
//package com.java2s; //License from project: Apache License import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; public class Main { public static String getLocalIpByInterfaceName(String interfaceName) throws SocketException { Enumeration<InetAddress> addressEnumeration = NetworkInterface.getByName(interfaceName).getInetAddresses(); while (addressEnumeration.hasMoreElements()) { InetAddress address = addressEnumeration.nextElement(); if (address instanceof Inet4Address) { return address.getHostAddress(); }//from ww w . j a va 2s . co m } return null; } }