com.cloud.utils.net.NetUtils.isIpv4()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(1.8k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中com.cloud.utils.net.NetUtils.isIpv4()方法的一些代码示例,展示了NetUtils.isIpv4()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NetUtils.isIpv4()方法的具体详情如下:
包路径:com.cloud.utils.net.NetUtils
类名称:NetUtils
方法名:isIpv4

NetUtils.isIpv4介绍

[英]Returns true if the given IP address is IPv4 or false if it is an IPv6. If it is an invalid IP address it throws an exception.
[中]如果给定的IP地址是IPv4,则返回true;如果是IPv6,则返回false。如果是无效的IP地址,则会引发异常。

代码示例

代码示例来源:origin: apache/cloudstack

  1. @Test(expected = IllegalArgumentException.class)
  2. public void testIsIpv4ExpectException2() {
  3. NetUtils.isIpv4("2001:db8:300::/64");
  4. }

代码示例来源:origin: apache/cloudstack

  1. @Test(expected = IllegalArgumentException.class)
  2. public void testIsIpv4ExpectException() {
  3. NetUtils.isIpv4("test");
  4. }

代码示例来源:origin: apache/cloudstack

  1. @Test
  2. public void testIsIpv4() {
  3. assertTrue(NetUtils.isIpv4("192.168.1.1"));
  4. assertFalse(NetUtils.isIpv4("2a01:4f8:130:2192::2"));
  5. }

代码示例来源:origin: apache/cloudstack

  1. @Override
  2. public void create() throws ResourceAllocationException {
  3. NicSecondaryIp result;
  4. IpAddresses requestedIpPair = new IpAddresses(ipAddr, null);
  5. if (!NetUtils.isIpv4(ipAddr)) {
  6. requestedIpPair = new IpAddresses(null, ipAddr);
  7. }
  8. try {
  9. result = _networkService.allocateSecondaryGuestIP(getNicId(), requestedIpPair);
  10. if (result != null) {
  11. setEntityId(result.getId());
  12. setEntityUuid(result.getUuid());
  13. }
  14. } catch (InsufficientAddressCapacityException e) {
  15. throw new InvalidParameterValueException("Allocating guest ip for nic failed : " + e.getMessage());
  16. }
  17. if (result == null) {
  18. throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign secondary ip to nic");
  19. }
  20. }
  21. }

代码示例来源:origin: apache/cloudstack

  1. if ((ipv4Address != null || NetUtils.isIpv4(network.getGateway()) && org.apache.commons.lang3.StringUtils.isBlank(ipv6Address))) {
  2. ipaddr = _ipAddrMgr.allocateGuestIP(network, ipv4Address);

相关文章

最新文章

更多

NetUtils类方法