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


Java SubnetUtils.setInclusiveHostCount方法代码示例

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


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

示例1: isIpInValidRange

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
/**
 * If the ip is in the same network as the cidr, it returns true
 *
 * @param ipAddress The ip address under test
 * @param cidr      The cidr that defines the expected network address
 * @param ipVersion
 * @return
 */
public static boolean isIpInValidRange(String ipAddress,
        String cidr, IPVersion ipVersion) {

    if (!IPVersion.IPv4.equals(ipVersion)) {
        throw new UnsupportedOperationException(
                "Support for IPv6 IP address is not yet implemented");
    }

    SubnetUtils utils = new SubnetUtils(cidr);
    utils.setInclusiveHostCount(true);

    if (!utils.getInfo().getAddress().equals(utils.getInfo().getNetworkAddress())) {
        String err = String.format("Invalid CIDR: %s. Host identifier of the"
                + " CIDR contains non zero bits.", cidr);
        throw new RuntimeException(err);
    }

    return utils.getInfo().isInRange(ipAddress);

}
 
开发者ID:vmware,项目名称:photon-model,代码行数:29,代码来源:SubnetValidator.java

示例2: isIpWithtInCidrRange

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
public static boolean isIpWithtInCidrRange(final String ipAddress, final String cidr) {
    if (!isValidIp4(ipAddress)) {
        return false;
    }
    if (!isValidIp4Cidr(cidr)) {
        return false;
    }
    if (cidr.equals("0.0.0.0/0")) {
        return true;
    }

    // check if the gatewayip is the part of the ip range being added.
    // RFC 3021 - 31-Bit Prefixes on IPv4 Point-to-Point Links
    //     GW              Netmask         Stat IP        End IP
    // 192.168.24.0 - 255.255.255.254 - 192.168.24.0 - 192.168.24.1
    // https://tools.ietf.org/html/rfc3021
    // Added by Wilder Rodrigues
    final SubnetUtils subnetUtils = new SubnetUtils(cidr);
    subnetUtils.setInclusiveHostCount(true);

    final boolean isInRange = subnetUtils.getInfo().isInRange(ipAddress);

    return isInRange;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:25,代码来源:NetUtils.java

示例3: testThatFilterAndTruncateViolatorsFiltersIPsInDoNotBlockRangeSet

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
@Test
public void testThatFilterAndTruncateViolatorsFiltersIPsInDoNotBlockRangeSet() {
    config.setRateLimitViolationBlacklistPeriodInMinutes(1);
    RangeSet<Integer> doNotAutoBlockIpRangeSet = TreeRangeSet.create();

    SubnetUtils subnetUtils = new SubnetUtils("50.39.100.193/32");
    subnetUtils.setInclusiveHostCount(true);
    SubnetUtils.SubnetInfo subnetInfo = subnetUtils.getInfo();
    Integer lowIpAsInt = subnetInfo.asInteger(subnetInfo.getLowAddress());
    Integer highIpAsInt = subnetInfo.asInteger(subnetInfo.getHighAddress());
    doNotAutoBlockIpRangeSet.add(Range.closed(lowIpAsInt, highIpAsInt));

    Map<String, ViolationMetaData> violators = new HashMap<>();
    violators.put("50.39.100.193", new ViolationMetaData(new Date(), 2));
    Map<String, ViolationMetaData> actual = processor.filterAndTruncateViolators(config, doNotAutoBlockIpRangeSet,
            violators);

    assertTrue("The violators map should be empty after filtering", actual.size() == 0);
}
 
开发者ID:Nike-Inc,项目名称:cerberus-serverless-components,代码行数:20,代码来源:RateLimitingProcessorTest.java

示例4: testThatProcessViolatorsDoesNotReAddWhatIsAlreadyBlocked

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
@Test
public void testThatProcessViolatorsDoesNotReAddWhatIsAlreadyBlocked() {
    String fakeIpSet = "foo";
    config.setRateLimitAutoBlackListIpSetId(fakeIpSet);

    List<SubnetUtils.SubnetInfo> currentlyAutoBlocked = new LinkedList<>();
    SubnetUtils subnetUtils = new SubnetUtils("192.168.0.1/32");
    subnetUtils.setInclusiveHostCount(true);
    SubnetUtils.SubnetInfo info = subnetUtils.getInfo();
    currentlyAutoBlocked.add(info);

    doReturn(currentlyAutoBlocked).when(processor).getIpSet(fakeIpSet);

    Map<String, ViolationMetaData> violators = new HashMap<>();
    violators.put("192.168.0.1", new ViolationMetaData(new Date(), 10));

    processor.processViolators(config, violators);

    verify(awswaf, times(0)).updateIPSet(isA(UpdateIPSetRequest.class));
}
 
开发者ID:Nike-Inc,项目名称:cerberus-serverless-components,代码行数:21,代码来源:RateLimitingProcessorTest.java

示例5: testThatProcessViolatorsAddsNewIpsToIpSet

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
@Test
public void testThatProcessViolatorsAddsNewIpsToIpSet() {
    String fakeIpSet = "foo";
    config.setRateLimitAutoBlackListIpSetId(fakeIpSet);
    doReturn(new LinkedList<>()).when(processor).getIpSet(fakeIpSet);
    Map<String, ViolationMetaData> violators = new HashMap<>();
    violators.put("192.168.0.1", new ViolationMetaData(new Date(), 10));

    processor.processViolators(config, violators);

    List<IPSetUpdate> expectedUpdates = new LinkedList<>();
    SubnetUtils subnetUtils = new SubnetUtils("192.168.0.1/32");
    subnetUtils.setInclusiveHostCount(true);
    SubnetUtils.SubnetInfo info = subnetUtils.getInfo();
    IPSetDescriptor descriptor = new IPSetDescriptor()
            .withType(IPSetDescriptorType.IPV4)
            .withValue(info.getCidrSignature());

    IPSetUpdate update = new IPSetUpdate().withIPSetDescriptor(descriptor).withAction(ChangeAction.INSERT);
    expectedUpdates.add(update);

    verify(awswaf, times(1)).updateIPSet(new UpdateIPSetRequest()
            .withIPSetId(config.getRateLimitAutoBlackListIpSetId())
            .withUpdates(expectedUpdates)
            .withChangeToken(CHANGE_TOKEN));
}
 
开发者ID:Nike-Inc,项目名称:cerberus-serverless-components,代码行数:27,代码来源:RateLimitingProcessorTest.java

示例6: getIgpPrefixMetric

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
/**
 * Lookup the IGP metric for the prefix (e.g. next hop) passed
 *
 * @param prefix            IP in print form (this is the next-hop)
 * @param igpMap            IGP RIB map
 *
 * @return null if no match, otherwise the column def list that matches is returned
 */
List<DbColumnDef> getIgpPrefixMetric(String prefix, Map<String, List<DbColumnDef>> igpMap) {
    List<DbColumnDef> found_cols = null;

    System.out.println("Lookup IGP metric cost for prefix " + prefix);

    for(Map.Entry<String, List<DbColumnDef>> row : igpMap.entrySet()) {
        // Prefix,PrefixLen,LocalPref,ASPath_Count,Origin,MED,NH
        List<DbColumnDef> cols = row.getValue();

        SubnetUtils subU = new SubnetUtils(cols.get(0).getValue() + '/' + cols.get(1).getValue());
        subU.setInclusiveHostCount(true);

        if (subU.getInfo().isInRange(prefix)) {
            System.out.println("    Found matching prefix, metric is " + cols.get(6).getValue());
            found_cols = cols;
            break;
        }
    }

    return found_cols;
}
 
开发者ID:OpenBMP,项目名称:db_rest,代码行数:30,代码来源:Orr.java

示例7: isIpWithInCidrRange

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
public static boolean isIpWithInCidrRange(final String ipAddress, final String cidr) {
    if (!isValidIp4(ipAddress)) {
        return false;
    }
    if (!isValidIp4Cidr(cidr)) {
        return false;
    }

    // check if the gatewayip is the part of the ip range being added.
    // RFC 3021 - 31-Bit Prefixes on IPv4 Point-to-Point Links
    //     GW              Netmask         Stat IP        End IP
    // 192.168.24.0 - 255.255.255.254 - 192.168.24.0 - 192.168.24.1
    // https://tools.ietf.org/html/rfc3021
    // Added by Wilder Rodrigues
    final SubnetUtils subnetUtils = new SubnetUtils(cidr);
    subnetUtils.setInclusiveHostCount(true);

    final boolean isInRange = subnetUtils.getInfo().isInRange(ipAddress);

    return isInRange;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:22,代码来源:NetUtils.java

示例8: getSubnetArray

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
public final static SubnetInfo[] getSubnetArray(String ips)
		throws IOException {
	if (ips == null)
		return null;
	StringReader sr = new StringReader(ips);
	try {
		List<String> lines = IOUtils.readLines(sr);
		if (lines == null)
			return null;
		SubnetInfo[] subnetArray = new SubnetInfo[lines.size()];
		int i = 0;
		for (String line : lines) {
			line = line.trim();
			if (line.isEmpty())
				continue;
			if (line.indexOf('/') == -1)
				line = line + "/32";
			SubnetUtils subnetUtils = new SubnetUtils(line);
			subnetUtils.setInclusiveHostCount(true);
			subnetArray[i++] = subnetUtils.getInfo();
		}
		return subnetArray;
	} finally {
		IOUtils.closeQuietly(sr);
	}
}
 
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:27,代码来源:NetworksUtils.java

示例9: getCidrHostAddress

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
public static String getCidrHostAddress(final String cidr) {
    final String[] cidrPair = cidr.split("\\/");
    final String address = cidrPair[0];
    final SubnetUtils subnetUtils = new SubnetUtils(cidr);
    subnetUtils.setInclusiveHostCount(false);

    if (isValidIp4(address) && subnetUtils.getInfo().isInRange(address)) {
        return address;
    }

    return null;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:13,代码来源:NetUtils.java

示例10: isNetworkorBroadcastIP

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
public static boolean isNetworkorBroadcastIP(final String ip, final String netmask) {
    final String cidr = getCidrFromGatewayAndNetmask(ip, netmask);
    final SubnetUtils subnetUtils = new SubnetUtils(cidr);
    subnetUtils.setInclusiveHostCount(false);
    final boolean isInRange = subnetUtils.getInfo().isInRange(ip);
    return !isInRange;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:8,代码来源:NetUtils.java

示例11: testThatProcessViolatorsRemovesIpsThatShouldNoLongerBeInIpSet

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
@Test
public void testThatProcessViolatorsRemovesIpsThatShouldNoLongerBeInIpSet() {
    String fakeIpSet = "foo";
    config.setRateLimitAutoBlackListIpSetId(fakeIpSet);

    List<SubnetUtils.SubnetInfo> currentlyAutoBlocked = new LinkedList<>();
    SubnetUtils subnetUtils = new SubnetUtils("192.168.0.1/32");
    subnetUtils.setInclusiveHostCount(true);
    SubnetUtils.SubnetInfo info = subnetUtils.getInfo();
    currentlyAutoBlocked.add(info);

    doReturn(currentlyAutoBlocked).when(processor).getIpSet(fakeIpSet);

    Map<String, ViolationMetaData> violators = new HashMap<>();

    processor.processViolators(config, violators);

    List<IPSetUpdate> expectedUpdates = new LinkedList<>();
    IPSetDescriptor descriptor = new IPSetDescriptor()
            .withType(IPSetDescriptorType.IPV4)
            .withValue(info.getCidrSignature());

    IPSetUpdate update = new IPSetUpdate().withIPSetDescriptor(descriptor).withAction(ChangeAction.DELETE);
    expectedUpdates.add(update);

    verify(awswaf, times(1)).updateIPSet(new UpdateIPSetRequest()
            .withIPSetId(config.getRateLimitAutoBlackListIpSetId())
            .withUpdates(expectedUpdates)
            .withChangeToken(CHANGE_TOKEN));
}
 
开发者ID:Nike-Inc,项目名称:cerberus-serverless-components,代码行数:31,代码来源:RateLimitingProcessorTest.java

示例12: testThatGetDoNotBlockRangeSetBuildsARangeSet

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
@Test
public void testThatGetDoNotBlockRangeSetBuildsARangeSet() {
    // stub the black list
    String black = "black";
    config.setManualBlackListIpSetId(black);
    List<SubnetUtils.SubnetInfo> blackList = Lists.newLinkedList();
    // 192.168.0.0-192.168.0.255
    SubnetUtils bSubnetUtils = new SubnetUtils("192.168.0.0/24");
    bSubnetUtils.setInclusiveHostCount(true);
    SubnetUtils.SubnetInfo bInfo = bSubnetUtils.getInfo();
    blackList.add(bInfo);
    doReturn(blackList).when(processor).getIpSet(black);

    // stub the white list
    String white = "white";
    config.setManualWhiteListIpSetId(white);
    List<SubnetUtils.SubnetInfo> whiteList = Lists.newLinkedList();
    // 192.150.0.0-192.150.0.255
    SubnetUtils wSubnetUtils = new SubnetUtils("192.150.0.0/24");
    wSubnetUtils.setInclusiveHostCount(true);
    SubnetUtils.SubnetInfo wInfo = wSubnetUtils.getInfo();
    whiteList.add(wInfo);
    doReturn(whiteList).when(processor).getIpSet(white);

    RangeSet<Integer> doNotBlock = processor.getDoNotBlockRangeSet(config);

    SubnetUtils utils = new SubnetUtils("0.0.0.0/24");
    Integer onTheBlackListLow = utils.getInfo().asInteger("192.168.0.0");
    Integer onTheBlackListHigh = utils.getInfo().asInteger("192.168.0.255");
    Integer onTheWhiteListLow = utils.getInfo().asInteger("192.150.0.0");
    Integer onTheWhiteListHigh = utils.getInfo().asInteger("192.150.0.255");
    Integer shouldBeBlocked = utils.getInfo().asInteger("192.168.1.1");

    assertTrue("192.168.0.0 is in the ip range represented by 192.168.0.0/24 and therefor should be in the doNotBlock range set", doNotBlock.contains(onTheBlackListLow));
    assertTrue("192.168.0.255 is in the ip range represented by 192.168.0.0/24 and therefor should be in the doNotBlock range set", doNotBlock.contains(onTheBlackListHigh));
    assertTrue("192.150.0.0 is in the ip range represented by 192.150.0.0/24 and therefor should be in the doNotBlock range set", doNotBlock.contains(onTheWhiteListLow));
    assertTrue("192.150.0.255 is in the ip range represented by 192.150.0.0/24 and therefor should be in the doNotBlock range set", doNotBlock.contains(onTheWhiteListHigh));
    assertFalse("192.168.1.1 is not in 192.168.0.0/24 or 192.150.0.0/24 and should not be in the doNotBlock range set", doNotBlock.contains(shouldBeBlocked));
}
 
开发者ID:Nike-Inc,项目名称:cerberus-serverless-components,代码行数:40,代码来源:RateLimitingProcessorTest.java

示例13: CriteriaIP

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
public CriteriaIP(String ipAddress, String mask, PacketDirection direction)
{
	this.ipAddress = ipAddress;
	this.direction = direction;
	
	SubnetUtils subnetUtils = new SubnetUtils(ipAddress, mask);
	subnetUtils.setInclusiveHostCount(true); //to allow one specific address with mask 255.255.255.255
	
	subnetInfo = subnetUtils.getInfo();
}
 
开发者ID:ck3ck3,项目名称:WhoWhatWhere,代码行数:11,代码来源:CriteriaIP.java

示例14: getSubnetRange

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
public static String getSubnetRange(String ip, String netmask)
{
	try
	{
		SubnetUtils subnetUtils = new SubnetUtils(ip, netmask);
		subnetUtils.setInclusiveHostCount(true); //to allow one specific address with mask 255.255.255.255
		
		return subnetUtils.getInfo().getLowAddress() + " - " + subnetUtils.getInfo().getHighAddress();
	}
	catch(IllegalArgumentException iae)
	{
		return null;
	}
}
 
开发者ID:ck3ck3,项目名称:WhoWhatWhere,代码行数:15,代码来源:NetworkSniffer.java

示例15: validate

import org.apache.commons.net.util.SubnetUtils; //导入方法依赖的package包/类
private void validate(APIAddIpRangeByNetworkCidrMsg msg) {
    try {
        SubnetUtils utils = new SubnetUtils(msg.getNetworkCidr());
        utils.setInclusiveHostCount(false);
        SubnetInfo subnet = utils.getInfo();
        if (subnet.getAddressCount() == 0) {
            throw new ApiMessageInterceptionException(argerr("%s is not an allowed network cidr, because it doesn't have usable ip range", msg.getNetworkCidr()));
        }
    } catch (IllegalArgumentException e) {
        throw new ApiMessageInterceptionException(argerr("%s is not a valid network cidr", msg.getNetworkCidr()));
    }

    IpRangeInventory ipr = IpRangeInventory.fromMessage(msg);
    validate(ipr);
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:16,代码来源:L3NetworkApiInterceptor.java


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