Package org.apache.commons.net.util

Examples of org.apache.commons.net.util.SubnetUtils


public class WildcardHelperTest {

    @Test
    public void testNullValues() {
       
        SubnetUtils s = new SubnetUtils("1.2.3.4/10");
        s = new SubnetUtils("1.2.3.4", "255.255.0.0");
       
        try{
            WildcardHelper.wildcardAsRegex(null);
            fail("should complain");
        } catch(IllegalArgumentException iae) {
View Full Code Here


public class SubnetWhitelistEntry implements WhitelistEntry {

    private final SubnetInfo subnetInfo;
   
    public SubnetWhitelistEntry(String cidrNotation) {
        subnetInfo = new SubnetUtils(cidrNotation).getInfo();
    }
View Full Code Here

    public SubnetWhitelistEntry(String cidrNotation) {
        subnetInfo = new SubnetUtils(cidrNotation).getInfo();
    }
   
    public SubnetWhitelistEntry(String ip, String subnetMask) {
        subnetInfo = new SubnetUtils(ip, subnetMask).getInfo();
    }
View Full Code Here

        Set<String> hosts = new HashSet<String>();
        for (String hostEntry : hostEntries) {
          //ip address range
          if (hostEntry.indexOf("/") > -1) {
            try {
              SubnetUtils subnet = new SubnetUtils(hostEntry);
              subnet.setInclusiveHostCount(true);
              cidrs.add(subnet.getInfo());
            } catch (IllegalArgumentException e) {
              LOG.warn("Invalid CIDR syntax : " + hostEntry);
              throw e;
            }
          } else if (InetAddresses.isInetAddress(hostEntry)) { //ip address
View Full Code Here

*/
public class SubnetUtilsExample {
   
    public static void main(String[] args) {
        String subnet = "192.168.0.1/29";
        SubnetUtils utils = new SubnetUtils(subnet);
        SubnetInfo info = utils.getInfo();
       
        System.out.printf("Subnet Information for %s:\n", subnet);
        System.out.println("--------------------------------------");
        System.out.printf("IP Address:\t\t\t%s\t[%s]\n", info.getAddress(),
                Integer.toBinaryString(info.asInteger(info.getAddress())));
View Full Code Here

      return new AnonymousMatch(privilege);
    } else if (CIDR_FORMAT_SHORT.matcher(host).matches()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Using CIDR match for '" + host + "' and " + privilege);
      }
      return new CIDRMatch(privilege, new SubnetUtils(host).getInfo());
    } else if (CIDR_FORMAT_LONG.matcher(host).matches()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Using CIDR match for '" + host + "' and " + privilege);
      }
      String[] pair = host.split("/");
      return new CIDRMatch(privilege,
          new SubnetUtils(pair[0], pair[1]).getInfo());
    } else if (host.contains("*") || host.contains("?") || host.contains("[")
        || host.contains("]")) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Using Regex match for '" + host + "' and " + privilege);
      }
View Full Code Here

            return false;
        }
        if (!isValidCIDR(cidr)) {
            return false;
        }
        SubnetUtils subnetUtils = new SubnetUtils(cidr);
        return subnetUtils.getInfo().isInRange(ipAddress);
    }
View Full Code Here

   * @return true if the given string is a subnet specified
   *     using CIDR notation, false otherwise
   */
  public static boolean isValidSubnet(String subnet) {
    try {
      new SubnetUtils(subnet);
      return true;
    } catch (IllegalArgumentException iae) {
      return false;
    }
  }
View Full Code Here

   * @throws IllegalArgumentException if subnet is invalid
   */
  public static List<InetAddress> getIPs(String subnet,
      boolean returnSubinterfaces) {
    List<InetAddress> addrs = new ArrayList<InetAddress>();
    SubnetInfo subnetInfo = new SubnetUtils(subnet).getInfo();
    Enumeration<NetworkInterface> nifs;

    try {
      nifs = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
View Full Code Here

   * @return true if the given string is a subnet specified
   *     using CIDR notation, false otherwise
   */
  public static boolean isValidSubnet(String subnet) {
    try {
      new SubnetUtils(subnet);
      return true;
    } catch (IllegalArgumentException iae) {
      return false;
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.net.util.SubnetUtils

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.