Here you can find the source of getAllMyHostIPV4Adresses()
public static Set<InetAddress> getAllMyHostIPV4Adresses() throws Exception
//package com.java2s; /*//from w w w .ja va2s. c om * (C) Copyright IBM Corp. 2008 * * LICENSE: Eclipse Public License v1.0 * http://www.eclipse.org/legal/epl-v10.html */ import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; import java.util.HashSet; import java.util.Set; public class Main { public static Set<InetAddress> getAllMyHostIPV4Adresses() throws Exception { Set<InetAddress> addresses = new HashSet<InetAddress>(); Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { Enumeration<InetAddress> ias = en.nextElement().getInetAddresses(); while (ias.hasMoreElements()) { InetAddress address = ias.nextElement(); if (isIPv4(stripToSlash(address.toString()))) addresses.add(address); } } return addresses; } public static boolean isIPv4(String ip) { return ip.matches("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+"); } public static String stripToSlash(String s) { int idx = s.indexOf('/'); return -1 == idx ? s : s.substring(idx + 1); } }