當前位置: 首頁>>代碼示例>>Java>>正文


Java InetAddressUtils.isIPv4Address方法代碼示例

本文整理匯總了Java中org.apache.http.conn.util.InetAddressUtils.isIPv4Address方法的典型用法代碼示例。如果您正苦於以下問題:Java InetAddressUtils.isIPv4Address方法的具體用法?Java InetAddressUtils.isIPv4Address怎麽用?Java InetAddressUtils.isIPv4Address使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.conn.util.InetAddressUtils的用法示例。


在下文中一共展示了InetAddressUtils.isIPv4Address方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLocalIpAddress

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的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() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {
                    return inetAddress.getHostAddress();
                }
            }
        }
    } catch (Exception ex) {
        Log.e("IP Address", ex.toString());
    }
    return null;
}
 
開發者ID:RomascuAndrei,項目名稱:BTNotifierAndroid,代碼行數:17,代碼來源:SettingsActivity.java

示例2: isDirServer

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
/**
 * Is the requested destination a dir router?
 *
 * @param sp {@link TCPStreamProperties} containing the destination infos
 * @return true if it is a directory server
 */
public boolean isDirServer(final TCPStreamProperties sp) {
    if (sp.getHostname() != null && InetAddressUtils.isIPv4Address(sp.getHostname())) {
        String[] octets = sp.getHostname().split("\\.");
        byte[] ip = new byte[4];
        ip[0] = (byte) Integer.parseInt(octets[0]);
        ip[1] = (byte) Integer.parseInt(octets[1]);
        ip[2] = (byte) Integer.parseInt(octets[2]);
        ip[3] = (byte) Integer.parseInt(octets[3]);

        final Router router = getValidRouterByIpAddressAndDirPort(new TcpipNetAddress(ip, sp.getPort()));
        if (router != null && (router.isDirv2HSDir() || router.isDirv2V2dir())) {
            return true;
        }
    }
    return false;
}
 
開發者ID:B4dT0bi,項目名稱:silvertunnel-ng,代碼行數:23,代碼來源:Directory.java

示例3: getAddr

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
public InetAddress getAddr()
{
	if (addr == null && hostname != null && !hostname.isEmpty() && InetAddressUtils.isIPv4Address(hostname))
	{
		try
		{
			String [] octets = hostname.split("\\.");
			byte [] ip = new byte [4];
			ip[0] = (byte) Integer.parseInt(octets[0]);
			ip[1] = (byte) Integer.parseInt(octets[1]);
			ip[2] = (byte) Integer.parseInt(octets[2]);
			ip[3] = (byte) Integer.parseInt(octets[3]);
			return InetAddress.getByAddress(ip);
		}
		catch (UnknownHostException e)
		{
			return addr;
		}
	}
	return addr;
}
 
開發者ID:B4dT0bi,項目名稱:silvertunnel-ng,代碼行數:22,代碼來源:TCPStreamProperties.java

示例4: getLocalIpAddress

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
/**
 * 獲取設備IP地址
 * 
 * @return 設備ip地址
 */
public static 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() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {   
                            
                           return inetAddress.getHostAddress().toString();   
                       }   
                   }   
            } 
       }catch (SocketException e) { 
           // TODO: handle exception 
       	Log.v("Steel", "WifiPreference IpAddress---error-" + e.toString());
       } 
        
       return null;  
   }
 
開發者ID:BigAppOS,項目名稱:BigApp_Discuz_Android,代碼行數:27,代碼來源:NetAddressUtil.java

示例5: getLocalIpAddress

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
/**
 * ��ȡ����ip
 */
private String getLocalIpAddress() {
	try {
		List<NetworkInterface> interfaces = Collections
				.list(NetworkInterface.getNetworkInterfaces());
		for (NetworkInterface intf : interfaces) {
			List<InetAddress> addrs = Collections.list(intf
					.getInetAddresses());
			for (InetAddress addr : addrs) {
				if (!addr.isLoopbackAddress()) {
					String sAddr = addr.getHostAddress().toUpperCase();
					boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr); 
                       if (isIPv4) {
                       	return sAddr;
                       }
				}
			}
		}
	} catch (Exception ex) {
		ex.printStackTrace();
	}
	return null;
}
 
開發者ID:lucky-code,項目名稱:Practice,代碼行數:26,代碼來源:MainActivity.java

示例6: getIPAddress

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
public String getIPAddress() {
    String ipaddress = "";
    try {
        Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
        while (en.hasMoreElements()) {
            NetworkInterface nif = en.nextElement();
            Enumeration<InetAddress> inet = nif.getInetAddresses();
            while (inet.hasMoreElements()) {
                InetAddress ip = inet.nextElement();
                if (!ip.isLoopbackAddress()
                        && InetAddressUtils.isIPv4Address(ip
                        .getHostAddress())) {
                    return ip.getHostAddress();
                }
            }

        }
    } catch (SocketException e) {
        Log.e("IP & PORT", "獲取本地ip地址失敗");
        e.printStackTrace();
    }
    return ipaddress;
}
 
開發者ID:1anc3r,項目名稱:AirFree-Client,代碼行數:24,代碼來源:TalkActivity.java

示例7: getIPAddress

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
public String getIPAddress() {
    String ipaddress = "";
    try {
        Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
        while (en.hasMoreElements()) {
            NetworkInterface nif = en.nextElement();
            Enumeration<InetAddress> inet = nif.getInetAddresses();
            while (inet.hasMoreElements()) {
                InetAddress ip = inet.nextElement();
                if (!ip.isLoopbackAddress()
                        && InetAddressUtils.isIPv4Address(ip
                        .getHostAddress())) {
                    return ipaddress = ip.getHostAddress();
                }
            }

        }
    } catch (SocketException e) {
        Log.e("IP & PORT", "獲取本地ip地址失敗");
        e.printStackTrace();
    }
    return ipaddress;
}
 
開發者ID:1anc3r,項目名稱:AirFree-Client,代碼行數:24,代碼來源:MainActivity.java

示例8: domainMatch

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
static boolean domainMatch(final String domain, final String host) {
    if (InetAddressUtils.isIPv4Address(host) || InetAddressUtils.isIPv6Address(host)) {
        return false;
    }
    final String normalizedDomain = domain.startsWith(".") ? domain.substring(1) : domain;
    if (host.endsWith(normalizedDomain)) {
        final int prefix = host.length() - normalizedDomain.length();
        // Either a full match or a prefix endidng with a '.'
        if (prefix == 0) {
            return true;
        }
        if (prefix > 1 && host.charAt(prefix - 1) == '.') {
            return true;
        }
    }
    return false;
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:18,代碼來源:BasicDomainHandler.java

示例9: getGPRSLocalIPAddress

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
public static String getGPRSLocalIPAddress() {
    try {
        Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
        while (en.hasMoreElements()) {
            NetworkInterface nif = en.nextElement();
            Enumeration<InetAddress> enumIpAddr = nif.getInetAddresses();
            while (enumIpAddr.hasMoreElements()) {
                InetAddress mInetAddress = enumIpAddr.nextElement();
                if (!mInetAddress.isLoopbackAddress()
                        && InetAddressUtils.isIPv4Address(mInetAddress.getHostAddress())) {
                    return mInetAddress.getHostAddress();
                }
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:hanks-zyh,項目名稱:FlyWoo,代碼行數:20,代碼來源:WifiUtils.java

示例10: getLocalIPAddress

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
private static void 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()
						&& InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {
					System.out.println("getHostAddress" + inetAddress.getHostAddress());
				}
			}
		}
	} catch (SocketException e) {
		e.printStackTrace();
	}
}
 
開發者ID:China-Victor,項目名稱:dgxtos,代碼行數:17,代碼來源:NetTools.java

示例11: checkField

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
public boolean checkField() {
    if(!currencyBySpinner) {
        //check address
        String address = mAdress.getText().toString().trim();
        if (!address.isEmpty()) {
            if (!InetAddressUtils.isIPv4Address(address) &&
                    !InetAddressUtils.isIPv6Address(address) &&
                    !Patterns.WEB_URL.matcher(address).matches()) {
                mAdress.setError(mContext.getString(R.string.invalid_peer_address));
                return false;
            }
        }

        //check port
        if (mPort.getText().toString().trim().isEmpty()) {
            mPort.setError(mContext.getString(R.string.port_cannot_be_empty));
            return false;
        } else if (Integer.parseInt(mPort.getText().toString()) <= 0 || 65535 <= Integer.parseInt(mPort.getText().toString())) {
            mPort.setError(mContext.getString(R.string.invalid_peer_port));
            return false;
        }
    }
    return true;
}
 
開發者ID:duniter,項目名稱:duniter-android-app,代碼行數:25,代碼來源:SelectorCurrencyView.java

示例12: getIPAddress

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
/**
 * Get IP address from first non-localhost interface
 *
 * @param useIPv4
 *            true=return ipv4, false=return ipv6
 * @return address or empty string
 * @throws SocketException
 */
public static String getIPAddress(boolean useIPv4) throws SocketException {
	List<NetworkInterface> interfaces = Collections.list(NetworkInterface
		.getNetworkInterfaces());
	for (NetworkInterface intf : interfaces) {
		List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
		for (InetAddress addr : addrs) {
			if (!addr.isLoopbackAddress()) {
				String sAddr = addr.getHostAddress();
				boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr);
				if (useIPv4) {
					if (isIPv4) return sAddr;
				} else {
					if (!isIPv4) {
						// drop ip6 port suffix
						int delim = sAddr.indexOf('%');
						return delim < 0 ? sAddr : sAddr
							.substring(0, delim);
					}
				}
			}
		}
	}
	return "";
}
 
開發者ID:bytebeats,項目名稱:base-android-utils,代碼行數:33,代碼來源:Addresses.java

示例13: getLocalHostIp

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
/**
 * 
 * 
 * @Title: getLocalHostIp
 * @Description: TODO 獲取設備IP地址
 * @author 李苜菲
 * @return
 * @return String
 * @throws @date
 *             2015-8-29下午4:56:18
 */
public static String getLocalHostIp() {
	String ipaddress = "";
	try {
		Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
		// 遍曆所用的網絡接口
		while (en.hasMoreElements()) {
			NetworkInterface nif = en.nextElement();// 得到每一個網絡接口綁定的所有ip
			Enumeration<InetAddress> inet = nif.getInetAddresses();
			// 遍曆每一個接口綁定的所有ip
			while (inet.hasMoreElements()) {
				InetAddress ip = inet.nextElement();
				if (!ip.isLoopbackAddress() && InetAddressUtils.isIPv4Address(ip.getHostAddress())) {
					return ipaddress = ip.getHostAddress();
				}
			}

		}
	} catch (SocketException e) {
		e.printStackTrace();
	}
	return ipaddress;

}
 
開發者ID:poomoo,項目名稱:eDao,代碼行數:35,代碼來源:Utity.java

示例14: getLocalHostIp

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
public static String getLocalHostIp() {
    String ipaddress = "127.0.0.1";
    try {
        Enumeration<NetworkInterface> en = NetworkInterface
                .getNetworkInterfaces();
        // 遍曆所用的網絡接口
        while (en.hasMoreElements()) {
            NetworkInterface nif = en.nextElement();// 得到每一個網絡接口綁定的所有ip
            Enumeration<InetAddress> inet = nif.getInetAddresses();
            // 遍曆每一個接口綁定的所有ip
            while (inet.hasMoreElements()) {
                InetAddress ip = inet.nextElement();
                if (!ip.isLoopbackAddress()
                        && InetAddressUtils.isIPv4Address(ip
                        .getHostAddress())) {
                    return ipaddress = ip.getHostAddress();
                }
            }

        }
    } catch (SocketException e) {
        return ipaddress;
    }
    return ipaddress;

}
 
開發者ID:MoonRune,項目名稱:CuiTrip,代碼行數:27,代碼來源:Utils.java

示例15: getInetAddress

import org.apache.http.conn.util.InetAddressUtils; //導入方法依賴的package包/類
public InetAddress getInetAddress() {
    try {
        Enumeration<NetworkInterface> networks;
        Enumeration<InetAddress> inets;
        NetworkInterface network;
        InetAddress inetAddress;

        for (networks = NetworkInterface.getNetworkInterfaces(); networks.hasMoreElements();) {
            network = networks.nextElement();
            for (inets = network.getInetAddresses(); inets.hasMoreElements();) {
                inetAddress = inets.nextElement();
                if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {

                    return inetAddress;
                }
            }

        }
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:lukeqsun,項目名稱:AirSpeakerMobile,代碼行數:25,代碼來源:AirPlayServer.java


注:本文中的org.apache.http.conn.util.InetAddressUtils.isIPv4Address方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。