hosthelper.java
来自「这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统」· Java 代码 · 共 46 行
JAVA
46 行
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 + =
减小字号Ctrl + -
显示快捷键?