📄 hosthelper.java
字号:
package net.sf.dz.util;import java.net.InetAddress;import java.net.NetworkInterface;import java.net.SocketException;import java.net.UnknownHostException;import java.util.Enumeration;import java.util.HashSet;import java.util.Set;public class HostHelper { public static boolean isLocalAddress(String address) throws SocketException, UnknownHostException { InetAddress targetAddress = InetAddress.getByName(address); // Since the network configuration is dynamic, we'd rather collect // the addresses right now return getLocalAddresses().contains(targetAddress); } public static final Set getLocalAddresses() throws SocketException { Set result = new HashSet(); for ( Enumeration e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements(); ) { NetworkInterface ni = (NetworkInterface)e.nextElement(); //complain(LOG_ALERT, getLogChannel(), "Interface: " + ni.getDisplayName()); for ( Enumeration e2 = ni.getInetAddresses(); e2.hasMoreElements(); ) { InetAddress niAddress = (InetAddress)e2.nextElement(); //complain(LOG_ALERT, getLogChannel(), "Address: " + niAddress); result.add(niAddress); } } return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -