当前位置: 首页>>代码示例>>Java>>正文


Java InetAddress.isLoopbackAddress方法代码示例

本文整理汇总了Java中java.net.InetAddress.isLoopbackAddress方法的典型用法代码示例。如果您正苦于以下问题:Java InetAddress.isLoopbackAddress方法的具体用法?Java InetAddress.isLoopbackAddress怎么用?Java InetAddress.isLoopbackAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.InetAddress的用法示例。


在下文中一共展示了InetAddress.isLoopbackAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getOneIPV4

import java.net.InetAddress; //导入方法依赖的package包/类
/** 获得IP信息 */
public static String getOneIPV4() {
	ArrayList<String> list = new ArrayList<String>();
	String result = "ip get failed";
	try {
		for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
			NetworkInterface intf = (NetworkInterface) en.nextElement();
			for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
				InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement();
				if (inetAddress instanceof Inet4Address) {
					if (!inetAddress.isLoopbackAddress()) {
						list.add(inetAddress.getHostAddress());
					}
				}
			}
		}
	} catch (SocketException ex) {
	}
	if (list.size() > 0)
		result = list.get(0);
	return result;
}
 
开发者ID:waylife,项目名称:ViewDebugHelper,代码行数:23,代码来源:NetworkUtil.java

示例2: getLocalIpAddressV4

import java.net.InetAddress; //导入方法依赖的package包/类
public static String getLocalIpAddressV4() {
        String ip = "";
        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    //if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress()))  //这里做了一步IPv4的判定
                    if (!inetAddress.isLoopbackAddress()
                            && inetAddress instanceof Inet4Address) {
                        ip = inetAddress.getHostAddress().toString();
                        return ip;
                    }
                }
            }
        } catch (SocketException e) {
//            Log.i("SocketException--->", ""+e.getLocalizedMessage());
            return "ip is error";
        }
        return ip;
    }
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:22,代码来源:NormalUtil.java

示例3: getGPRSIpAddress

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * 获取GPRS连接的情况的IP
 * 
 * @return
 */
private static String getGPRSIpAddress()
{
    
    String ip = "";
    try
    {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
        {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
            {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress() && inetAddress.getHostAddress() != null)
                {
                    ip = inetAddress.getHostAddress().toString();
                }
            }
        }
    }
    catch (SocketException ex)
    {
        Log.e("WifiPreference IpAddress", ex.toString());
    }
    return ip == null ? "" : ip;
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:31,代码来源:MIP_NetworkUtils.java

示例4: displayStackTraces

import java.net.InetAddress; //导入方法依赖的package包/类
public boolean displayStackTraces() {
    ServletStackTraces mode = deployment.getDeploymentInfo().getServletStackTraces();
    if (mode == ServletStackTraces.NONE) {
        return false;
    } else if (mode == ServletStackTraces.ALL) {
        return true;
    } else {
        InetSocketAddress localAddress = getExchange().getSourceAddress();
        if(localAddress == null) {
            return false;
        }
        InetAddress address = localAddress.getAddress();
        if(address == null) {
            return false;
        }
        if(!address.isLoopbackAddress()) {
            return false;
        }
        return !getExchange().getRequestHeaders().contains(Headers.X_FORWARDED_FOR);
    }

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:ServletRequestContext.java

示例5: getIp

import java.net.InetAddress; //导入方法依赖的package包/类
public static String getIp() {
    try {
        for (Enumeration<NetworkInterface> enNetI = NetworkInterface
                .getNetworkInterfaces(); enNetI.hasMoreElements(); ) {
            NetworkInterface netI = enNetI.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = netI
                    .getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) {
                    return inetAddress.getHostAddress();
                }
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }
    return "";
}
 
开发者ID:OddCN,项目名称:screen-share-to-browser,代码行数:19,代码来源:NetUtil.java

示例6: getDevicesIp

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * 获取设备IP
 *
 * @return
 */
public String getDevicesIp() {
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en
                .hasMoreElements(); ) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr
                    .hasMoreElements(); ) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                    return inetAddress.getHostAddress().toString();
                }
            }
        }
    } catch (SocketException ex) {
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:jopenbox,项目名称:android-lite-utils,代码行数:24,代码来源:DevicesUtils.java

示例7: getMobileIP

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * 获取GSM网络的IP地址
 */
public static String getMobileIP() {
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
            NetworkInterface intf = (NetworkInterface) en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                    String ipaddress = inetAddress.getHostAddress().toString();
                    return ipaddress;
                }
            }
        }
    } catch (SocketException ex) {
        Log.e("getMobileIP", "Exception in Get IP Address: " + ex.toString());
    }
    return "";
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:21,代码来源:Network.java

示例8: getLocalIpAddress

import java.net.InetAddress; //导入方法依赖的package包/类
public String getLocalIpAddress() {
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress() && inetAddress.isSiteLocalAddress()) {
                    return inetAddress.getHostAddress();
                }
            }
        }
    } catch (SocketException ex) {
        ex.printStackTrace();
    }
    return "0.0.0.0";
}
 
开发者ID:Crixec,项目名称:ADBToolKitsInstaller,代码行数:17,代码来源:MainActivity.java

示例9: getLocalIpAddress

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * getLocalIpAddress
 * @return
 */
public static String getLocalIpAddress() {
    String ret = "";
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                    ret = inetAddress.getHostAddress().toString();
                }
            }
        }
    } catch (SocketException ex) {
        ex.printStackTrace();
    }
    return ret;
}
 
开发者ID:yzzslow0,项目名称:Ec2m,代码行数:22,代码来源:NetUtil.java

示例10: isValidAddress

import java.net.InetAddress; //导入方法依赖的package包/类
private static boolean isValidAddress(InetAddress address) {
    if(address != null && !address.isLoopbackAddress()) {
        String name = address.getHostAddress();
        return name != null &&!LOCAL_IP_PATTERN.matcher(name).matches()&&!name.equalsIgnoreCase("localhost")&& !"0.0.0.0".equals(name) && !"192.168.122.1".equals(name)&& !"127.0.0.1".equals(name) && IP_PATTERN.matcher(name).matches();
    } else {
        return false;
    }
}
 
开发者ID:zhangkewei,项目名称:dubbo-transaction,代码行数:9,代码来源:NetworkUtils.java

示例11: isLocal

import java.net.InetAddress; //导入方法依赖的package包/类
public boolean isLocal() {
	InetAddress a = address.getAddress();
	if (a.isLinkLocalAddress() || a.isLoopbackAddress() || a.isSiteLocalAddress()) {
		log.error("Loopback address: {}", a);
		return true;
	}
	return false;
}
 
开发者ID:AidosKuneen,项目名称:aidos-node,代码行数:9,代码来源:Peers.java

示例12: formatAddress

import java.net.InetAddress; //导入方法依赖的package包/类
/** format internet address: java's default doesn't include everything useful */
private static String formatAddress(InterfaceAddress interfaceAddress) throws IOException {
    StringBuilder sb = new StringBuilder();

    InetAddress address = interfaceAddress.getAddress();
    if (address instanceof Inet6Address) {
        sb.append("inet6 ");
        sb.append(NetworkAddress.format(address));
        sb.append(" prefixlen:");
        sb.append(interfaceAddress.getNetworkPrefixLength());
    } else {
        sb.append("inet ");
        sb.append(NetworkAddress.format(address));
        int netmask = 0xFFFFFFFF << (32 - interfaceAddress.getNetworkPrefixLength());
        sb.append(" netmask:" + NetworkAddress.format(InetAddress.getByAddress(new byte[] {
                (byte)(netmask >>> 24),
                (byte)(netmask >>> 16 & 0xFF),
                (byte)(netmask >>> 8 & 0xFF),
                (byte)(netmask & 0xFF)
        })));
        InetAddress broadcast = interfaceAddress.getBroadcast();
        if (broadcast != null) {
            sb.append(" broadcast:" + NetworkAddress.format(broadcast));
        }
    }
    if (address.isLoopbackAddress()) {
        sb.append(" scope:host");
    } else if (address.isLinkLocalAddress()) {
        sb.append(" scope:link");
    } else if (address.isSiteLocalAddress()) {
        sb.append(" scope:site");
    }
    return sb.toString();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:IfConfig.java

示例13: isValidAddress

import java.net.InetAddress; //导入方法依赖的package包/类
private static boolean isValidAddress(InetAddress address) {
    if (address == null || address.isLoopbackAddress())
        return false;
    String name = address.getHostAddress();
    return (name != null 
            && ! ANYHOST.equals(name)
            && ! LOCALHOST.equals(name) 
            && IP_PATTERN.matcher(name).matches());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:NetUtils.java

示例14: getIPAddress

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * 获取IP地址
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.INTERNET"/>}</p>
 *
 * @param useIPv4 是否用IPv4
 * @return IP地址
 */
public static String getIPAddress(boolean useIPv4) {
    try {
        for (Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); nis.hasMoreElements(); ) {
            NetworkInterface ni = nis.nextElement();
            // 防止小米手机返回10.0.2.15
            if (!ni.isUp())
                continue;
            for (Enumeration<InetAddress> addresses = ni.getInetAddresses(); addresses.hasMoreElements(); ) {
                InetAddress inetAddress = addresses.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                    String hostAddress = inetAddress.getHostAddress();
                    boolean isIPv4 = hostAddress.indexOf(':') < 0;
                    if (useIPv4) {
                        if (isIPv4)
                            return hostAddress;
                    } else {
                        if (!isIPv4) {
                            int index = hostAddress.indexOf('%');
                            return index < 0 ? hostAddress.toUpperCase() : hostAddress.substring(0, index).toUpperCase();
                        }
                    }
                }
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:ChunweiDu,项目名称:Utils,代码行数:37,代码来源:NetworkUtil.java

示例15: getIPAddress

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * 获取IP地址
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.INTERNET"/>}</p>
 *
 * @param useIPv4 是否用IPv4
 * @return IP地址
 */
public static String getIPAddress(boolean useIPv4) {
    try {
        for (Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); nis.hasMoreElements(); ) {
            NetworkInterface ni = nis.nextElement();
            // 防止小米手机返回10.0.2.15
            if (!ni.isUp()) continue;
            for (Enumeration<InetAddress> addresses = ni.getInetAddresses(); addresses.hasMoreElements(); ) {
                InetAddress inetAddress = addresses.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                    String hostAddress = inetAddress.getHostAddress();
                    boolean isIPv4 = hostAddress.indexOf(':') < 0;
                    if (useIPv4) {
                        if (isIPv4) return hostAddress;
                    } else {
                        if (!isIPv4) {
                            int index = hostAddress.indexOf('%');
                            return index < 0 ? hostAddress.toUpperCase() : hostAddress.substring(0, index).toUpperCase();
                        }
                    }
                }
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:StickyTolt,项目名称:ForeverLibrary,代码行数:35,代码来源:NetworkUtils.java


注:本文中的java.net.InetAddress.isLoopbackAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。