集册 Java实例教程 返回没有本地作用域(环回等)的所有地址的集合。

返回没有本地作用域(环回等)的所有地址的集合。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

456
返回没有本地作用域(环回等)的所有地址的集合。

//package com.nowjava;

import java.net.InetAddress;


import java.util.ArrayList;//nowjava - 时  代  Java

import java.util.Collection;


public class Main {

    /**

     * Returns a collection of all addresses which do not have a local scope (loopbacks etc).

     * @param addresses all addresse

     * @return the addresses which are not loopbacks/linklocal

     */

    public static Collection<InetAddress> getExternalAddresses(

            InetAddress[] addresses) {

        ArrayList<InetAddress> result = new ArrayList<InetAddress>();

        for (InetAddress addr : addresses) {

            if (addr.isAnyLocalAddress() || addr.isLinkLocalAddress()

                    || addr.isLoopbac
展开阅读全文