Example usage for org.apache.commons.net.util SubnetUtils SubnetUtils

List of usage examples for org.apache.commons.net.util SubnetUtils SubnetUtils

Introduction

In this page you can find the example usage for org.apache.commons.net.util SubnetUtils SubnetUtils.

Prototype

public SubnetUtils(String address, String mask) 

Source Link

Document

Constructor that takes a dotted decimal address and a dotted decimal mask.

Usage

From source file:com.ardikars.opennetcut.app.NetworkScanner.java

public NetworkScanner(PacketHandler handler) {
    SubnetUtils su = new SubnetUtils(StaticField.NETWORK_ADDRESS.toString(),
            StaticField.NETMASK_ADDRESS.toString());

    String[] strips = su.getInfo().getAllAddresses();
    for (String ip : strips) {
        ips.add(Inet4Address.valueOf(ip.trim()));
    }/*w  w  w.j  a v a  2s.  c  om*/
    this.handler = handler;
    this.index = 0;
}

From source file:com.naryx.tagfusion.expression.function.ext.ip.ipAsInteger.java

public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException {
    String ipaddress = getNamedStringParam(argStruct, "ip", null);
    if (ipaddress == null)
        throwException(_session, "Missing ip paramter");

    return new cfNumberData(new SubnetUtils("10.0.0.1", "255.255.255.255").getInfo().asInteger(ipaddress));
}

From source file:com.vmware.photon.controller.clustermanager.templates.HarborNodeTemplate.java

public FileTemplate createUserDataTemplate(String scriptDirectory, Map<String, String> properties) {
    Preconditions.checkNotNull(scriptDirectory, "scriptDirectory cannot be null");
    Preconditions.checkNotNull(properties, "properties cannot be null");

    String ipAddress = properties.get(IP_PROPERTY);
    String netmask = properties.get(NETMASK_PROPERTY);
    String cidrSignature = new SubnetUtils(ipAddress, netmask).getInfo().getCidrSignature();

    Map<String, String> parameters = new HashMap<>();
    parameters.put("$DNS", "DNS=" + properties.get(DNS_PROPERTY));
    parameters.put("$GATEWAY", properties.get(GATEWAY_PROPERTY));
    parameters.put("$ADDRESS", cidrSignature);
    parameters.put("$HARBOR_PORT", String.valueOf(ClusterManagerConstants.Harbor.HARBOR_PORT));
    parameters.put("$LOCAL_HOSTNAME", getVmName(properties));
    parameters.put("$SSH_KEY", properties.get(SSH_KEY_PROPERTY));
    parameters.put("$ADMIN_PASSWORD", properties.get(ADMIN_PASSWORD_PROPERTY));

    FileTemplate template = new FileTemplate();
    template.filePath = Paths.get(scriptDirectory, USER_DATA_TEMPLATE).toString();
    template.parameters = parameters;/*from w w w.j a va  2 s.  com*/
    return template;
}

From source file:cc.arduino.net.PACSupportMethods.java

public boolean isInNet(String host, String pattern, String mask) throws UnknownHostException {
    SubnetUtils subnetUtils = new SubnetUtils(pattern, mask);
    subnetUtils.setInclusiveHostCount(true);
    return new CIDRUtils(subnetUtils.getInfo().getCidrSignature()).isInRange(host);
}

From source file:com.vmware.photon.controller.clustermanager.templates.KubernetesMasterNodeTemplate.java

public FileTemplate createUserDataTemplate(String scriptDirectory, Map<String, String> properties) {
    Preconditions.checkNotNull(scriptDirectory, "scriptDirectory cannot be null");
    Preconditions.checkNotNull(properties, "properties cannot be null");

    List<String> etcdIps = NodeTemplateUtils.deserializeAddressList(properties.get(ETCD_IPS_PROPERTY));
    String ipAddress = properties.get(MASTER_IP_PROPERTY);
    String netmask = properties.get(NETMASK_PROPERTY);
    String cidrSignature = new SubnetUtils(ipAddress, netmask).getInfo().getCidrSignature();

    Map<String, String> parameters = new HashMap<>();
    parameters.put("$ETCD_QUORUM", NodeTemplateUtils.createEtcdQuorumString(etcdIps));
    parameters.put("$DNS", "DNS=" + properties.get(DNS_PROPERTY));
    parameters.put("$GATEWAY", properties.get(GATEWAY_PROPERTY));
    parameters.put("$ADDRESS", cidrSignature);
    parameters.put("$CONTAINER_NETWORK", properties.get(CONTAINER_NETWORK_PROPERTY));
    parameters.put("$KUBERNETES_PORT", String.valueOf(ClusterManagerConstants.Kubernetes.API_PORT));
    parameters.put("$LOCAL_HOSTNAME", getVmName(properties));

    FileTemplate template = new FileTemplate();
    template.filePath = Paths.get(scriptDirectory, MASTER_USER_DATA_TEMPLATE).toString();
    template.parameters = parameters;// w ww. ja va 2s. co m
    return template;
}

From source file:com.vmware.photon.controller.clustermanager.templates.ZookeeperNodeTemplate.java

public FileTemplate createUserDataTemplate(String scriptDirectory, Map<String, String> properties) {
    Preconditions.checkNotNull(scriptDirectory, "scriptDirectory cannot be null");
    Preconditions.checkNotNull(properties, "properties cannot be null");

    String dns = properties.get(DNS_PROPERTY);
    String gateway = properties.get(GATEWAY_PROPERTY);
    String netmask = properties.get(NETMASK_PROPERTY);
    String nodeIndexStr = properties.get(NodeTemplateUtils.NODE_INDEX_PROPERTY);
    List<String> zookeeperIps = NodeTemplateUtils
            .deserializeAddressList(properties.get(ZOOKEEPER_IPS_PROPERTY));

    int nodeIndex = Integer.parseInt(nodeIndexStr);

    String ipAddress = zookeeperIps.get(nodeIndex);
    String cidrSignature = new SubnetUtils(ipAddress, netmask).getInfo().getCidrSignature();
    String zkParameters = createZookeeperParameters(zookeeperIps);

    Map<String, String> parameters = new HashMap();
    parameters.put("$DNS", "DNS=" + dns);
    parameters.put("$GATEWAY", gateway);
    parameters.put("$ZK_ID", Integer.toString(nodeIndex + 1));
    parameters.put("$ADDRESS", cidrSignature);
    parameters.put("$ZK_PARAMETERS", zkParameters);

    FileTemplate template = new FileTemplate();
    template.filePath = Paths.get(scriptDirectory, ZOOKEEPER_USER_DATA_TEMPLATE).toString();
    template.parameters = parameters;/*  w  w w.  j  ava  2 s  .c o  m*/
    return template;
}

From source file:com.vmware.photon.controller.clustermanager.templates.EtcdNodeTemplate.java

public FileTemplate createUserDataTemplate(String scriptDirectory, Map<String, String> properties) {
    Preconditions.checkNotNull(scriptDirectory, "scriptDirectory cannot be null");
    Preconditions.checkNotNull(properties, "properties cannot be null");

    String dns = properties.get(DNS_PROPERTY);
    String gateway = properties.get(GATEWAY_PROPERTY);
    String netmask = properties.get(NETMASK_PROPERTY);
    String nodeIndexStr = properties.get(NodeTemplateUtils.NODE_INDEX_PROPERTY);

    int nodeIndex = Integer.parseInt(nodeIndexStr);
    List<String> etcdIps = NodeTemplateUtils.deserializeAddressList(properties.get(ETCD_IPS_PROPERTY));

    String ipAddress = etcdIps.get(nodeIndex);
    String cidrSignature = new SubnetUtils(ipAddress, netmask).getInfo().getCidrSignature();
    String etcdParameters = createEtcdParameters(etcdIps);

    Map<String, String> parameters = new HashMap();
    parameters.put("$DNS", "DNS=" + dns);
    parameters.put("$GATEWAY", gateway);
    parameters.put("$ETCD_ID", Integer.toString(nodeIndex));
    parameters.put("$ADDRESS", cidrSignature);
    parameters.put("$ETCD_PARAMETERS", etcdParameters);
    parameters.put("$ETCD_PORT", Integer.toString(ClusterManagerConstants.Swarm.ETCD_PORT));
    parameters.put("$ETCD_PEER_PORT", Integer.toString(ClusterManagerConstants.Swarm.ETCD_PEER_PORT));

    FileTemplate template = new FileTemplate();
    template.filePath = Paths.get(scriptDirectory, ETCD_USER_DATA_TEMPLATE).toString();
    template.parameters = parameters;//from   w  w w .  ja v a  2  s  . com
    return template;
}

From source file:com.vmware.photon.controller.clustermanager.templates.SwarmEtcdNodeTemplate.java

public FileTemplate createUserDataTemplate(String scriptDirectory, Map<String, String> properties) {
    Preconditions.checkNotNull(scriptDirectory, "scriptDirectory cannot be null");
    Preconditions.checkNotNull(properties, "properties cannot be null");

    String dns = properties.get(DNS_PROPERTY);
    String gateway = properties.get(GATEWAY_PROPERTY);
    String netmask = properties.get(NETMASK_PROPERTY);
    String nodeIndexStr = properties.get(NodeTemplateUtils.NODE_INDEX_PROPERTY);

    int nodeIndex = Integer.parseInt(nodeIndexStr);
    List<String> etcdIps = NodeTemplateUtils.deserializeAddressList(properties.get(ETCD_IPS_PROPERTY));

    String ipAddress = etcdIps.get(nodeIndex);
    String cidrSignature = new SubnetUtils(ipAddress, netmask).getInfo().getCidrSignature();
    String etcdParameters = createEtcdParameters(etcdIps);

    Map<String, String> parameters = new HashMap<>();
    parameters.put("$DNS", "DNS=" + dns);
    parameters.put("$GATEWAY", gateway);
    parameters.put("$ETCD_ID", Integer.toString(nodeIndex));
    parameters.put("$ADDRESS", cidrSignature);
    parameters.put("$ETCD_PARAMETERS", etcdParameters);
    parameters.put("$ETCD_PORT", Integer.toString(ClusterManagerConstants.Swarm.ETCD_PORT));
    parameters.put("$ETCD_PEER_PORT", Integer.toString(ClusterManagerConstants.Swarm.ETCD_PEER_PORT));

    FileTemplate template = new FileTemplate();
    template.filePath = Paths.get(scriptDirectory, ETCD_USER_DATA_TEMPLATE).toString();
    template.parameters = parameters;//from  w  ww .  ja  v a2  s.  c om
    return template;
}

From source file:com.vmware.photon.controller.clustermanager.templates.KubernetesEtcdNodeTemplate.java

public FileTemplate createUserDataTemplate(String scriptDirectory, Map<String, String> properties) {
    Preconditions.checkNotNull(scriptDirectory, "scriptDirectory cannot be null");
    Preconditions.checkNotNull(properties, "properties cannot be null");

    String dns = properties.get(DNS_PROPERTY);
    String gateway = properties.get(GATEWAY_PROPERTY);
    String netmask = properties.get(NETMASK_PROPERTY);
    String nodeIndexStr = properties.get(NodeTemplateUtils.NODE_INDEX_PROPERTY);
    String sshKey = properties.get(SSH_KEY_PROPERTY);

    int nodeIndex = Integer.parseInt(nodeIndexStr);
    List<String> etcdIps = NodeTemplateUtils.deserializeAddressList(properties.get(ETCD_IPS_PROPERTY));

    String ipAddress = etcdIps.get(nodeIndex);
    String cidrSignature = new SubnetUtils(ipAddress, netmask).getInfo().getCidrSignature();
    String etcdParameters = createEtcdParameters(etcdIps);
    // This the the URL we advertise to our peers.
    String etcdPeerURL = createEtcdPeerUrl(ipAddress);
    String etcdAdvertiseURL = createEtcdAdvertiseUrl(ipAddress);

    Map<String, String> parameters = new HashMap<>();
    parameters.put("$DNS", "DNS=" + dns);
    parameters.put("$GATEWAY", gateway);
    parameters.put("$ETCD_ID", Integer.toString(nodeIndex));
    parameters.put("$ADDRESS", cidrSignature);
    parameters.put("$ETCD_PARAMETERS", etcdParameters);
    parameters.put("$ETCD_PORT", Integer.toString(ClusterManagerConstants.Swarm.ETCD_PORT));
    parameters.put("$ETCD_PEER_PORT", Integer.toString(ClusterManagerConstants.Swarm.ETCD_PEER_PORT));
    parameters.put("$SSH_KEY", sshKey);
    parameters.put("$ETCD_PEER_URL", etcdPeerURL);
    parameters.put("$ETCD_ADVERTISE_URL", etcdAdvertiseURL);

    FileTemplate template = new FileTemplate();
    template.filePath = Paths.get(scriptDirectory, ETCD_USER_DATA_TEMPLATE).toString();
    template.parameters = parameters;// www . j  a v  a2  s  .  c  o  m
    return template;
}

From source file:com.naryx.tagfusion.expression.function.ext.ip.ipGetCount.java

/**
 * Gets the SubnetInfo block from the input parameters
 * @param _session//from  w ww. j  a  va  2  s . c  o m
 * @param argStruct
 * @return
 * @throws cfmRunTimeException
 */
protected SubnetInfo getInfo(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException {
    String ipaddress = getNamedStringParam(argStruct, "ip", null);
    if (ipaddress == null)
        throwException(_session, "Missing ip paramter");

    if (ipaddress.lastIndexOf("/") == -1) {
        String mask = getNamedStringParam(argStruct, "mask", null);
        if (mask == null)
            throwException(_session, "Since IP address is not in CIDR notation, please provide a mask");

        return new SubnetUtils(ipaddress, mask).getInfo();
    } else
        return new SubnetUtils(ipaddress).getInfo();
}