예제 #1
0
 /**
  * Sets the Subnet's Netmask in Decimal format.<br>
  * i.e.: setNetMask("255.255.255.0");
  *
  * @param netMask a network mask
  */
 private void setNetMask(String netMask) {
   StringTokenizer nm = new StringTokenizer(netMask, ".");
   int i = 0;
   int[] netmask = new int[4];
   while (nm.hasMoreTokens()) {
     netmask[i] = Integer.parseInt(nm.nextToken());
     i++;
   }
   int mask1 = 0;
   for (i = 0; i < 4; i++) {
     mask1 += Integer.bitCount(netmask[i]);
   }
   setCidrNetMask(mask1);
 }
예제 #2
0
  /**
   * Sets the Network Address in either CIDR or Decimal Notation.<br>
   * i.e.: setNetAddress("1.1.1.1/24"); or<br>
   * setNetAddress("1.1.1.1/255.255.255.0");<br>
   *
   * @param netAddress a network address as string.
   * @throws UnknownHostException
   */
  private void setNetAddress(String netAddress) throws UnknownHostException {
    Vector<Object> vec = new Vector<Object>();
    StringTokenizer st = new StringTokenizer(netAddress, "/");
    while (st.hasMoreTokens()) {
      vec.add(st.nextElement());
    }

    if (vec.get(1).toString().length() < 3) {
      setNetId(vec.get(0).toString());
      setCidrNetMask(Integer.parseInt(vec.get(1).toString()));
    } else {
      setNetId(vec.get(0).toString());
      setNetMask(vec.get(1).toString());
    }
  }
예제 #3
0
 /**
  * Sets the Network Address in CIDR Notation.
  *
  * @param inetAddress
  * @param cidrNetMask
  */
 private void setNetAddress(InetAddress inetAddress, int cidrNetMask) {
   setNetId(inetAddress);
   setCidrNetMask(cidrNetMask);
 }