當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。