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


Java InetAddressUtils类代码示例

本文整理汇总了Java中org.apache.http.conn.util.InetAddressUtils的典型用法代码示例。如果您正苦于以下问题:Java InetAddressUtils类的具体用法?Java InetAddressUtils怎么用?Java InetAddressUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: setValidationListener

import org.apache.http.conn.util.InetAddressUtils; //导入依赖的package包/类
private void setValidationListener(String prefName) {
    EditTextPreference edit_Pref = (EditTextPreference) getPreferenceScreen()
                    .findPreference(prefName);

    edit_Pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // put validation here..
            if (((String) newValue).isEmpty()
                            || InetAddressUtils.isIPv4Address((String) newValue)) {
                return true;
            } else {
                Commons.showMessage("ERROR:\nWrong IP format!", getActivity());
                return false;
            }
        }
    });
}
 
开发者ID:vaginessa,项目名称:RepWifiApp,代码行数:20,代码来源:SettingsActivity.java

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例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 ip.getHostAddress();
                }
            }

        }
    } catch (SocketException e) {
        Log.e("IP & PORT", "获取本地ip地址失败");
        e.printStackTrace();
    }
    return ipaddress;
}
 
开发者ID:1anc3r,项目名称:AirFree-Client,代码行数:24,代码来源:TalkActivity.java

示例8: 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

示例9: 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

示例10: 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

示例11: getMulticastIp

import org.apache.http.conn.util.InetAddressUtils; //导入依赖的package包/类
public InetAddress getMulticastIp() {
	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) {
						sAddr = sAddr.substring(0, sAddr.lastIndexOf('.') + 1) + "255";
						Log.d(Globals.TAG, "Multicast IP: " + sAddr);
						return InetAddress.getByName(sAddr);
					}
				}
			}
		}
	} catch (Exception e) {
		Log.d(Globals.TAG, "There was an error retrieving your IP. Aborted.");
	}
	return null;
}
 
开发者ID:dks-rub,项目名称:meshchat,代码行数:23,代码来源:MessageSender.java

示例12: 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

示例13: 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

示例14: 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
 */
public static String getIPAddress(boolean useIPv4) {
  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 (useIPv4) {
            if (isIPv4)
              return sAddr;
          } else {
            if (!isIPv4) {
              int delim = sAddr.indexOf('%'); // drop ip6 port suffix
              return delim < 0 ? sAddr : sAddr.substring(0, delim);
            }
          }
        }
      }
    }
  } catch (Exception ignored) {
  } // for now eat exceptions
  return "";
}
 
开发者ID:creativepsyco,项目名称:intercom-android-sdk,代码行数:32,代码来源:NetworkUtils.java

示例15: 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


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