Here you can find the source of getAllIp()
Parameter | Description |
---|---|
SocketException | I/O error occurs |
public static List<String> getAllIp() throws SocketException
//package com.java2s; /*/*ww w.ja va 2 s.c om*/ License: blueprint-sdk is licensed under the terms of Eclipse Public License(EPL) v1.0 (http://www.eclipse.org/legal/epl-v10.html) Distribution: Repository - https://github.com/lempel/blueprint-sdk.git Blog - http://lempel.egloos.com */ import java.net.*; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; public class Main { /** * @return list of all available ip address * @throws SocketException I/O error occurs */ public static List<String> getAllIp() throws SocketException { List<String> result = new ArrayList<>(); Enumeration<NetworkInterface> infs = NetworkInterface.getNetworkInterfaces(); while (infs.hasMoreElements()) { NetworkInterface inf = infs.nextElement(); if (!inf.isUp() || inf.isVirtual()) { continue; } Enumeration<InetAddress> addrs = inf.getInetAddresses(); while (addrs.hasMoreElements()) { InetAddress addr = addrs.nextElement(); String ip = addr.getHostAddress(); if ("0.0.0.0".equals(ip) || "::0".equals(ip)) { continue; } result.add(ip); } } return result; } }