当给定的地址是本地地址时返回true。
/** 时代Java公众号 - N o w J a v a . c o m 提供 **/ //package com.nowjava; import java.net.InetAddress; public class Main { /** * Returns true when the given address is a local address. * @param addr address * @return true when the given address is a local address */ public static boolean hasLocalScope(InetAddress addr) { if (addr == null) throw new IllegalArgumentException("Must not be null!"); return (addr.isAnyLocalAddress() || addr.isLinkLocalAddress() || addr .isLoopbackAddress()); } }