List of usage examples for org.apache.commons.net.util SubnetUtils SubnetUtils
public SubnetUtils(String cidrNotation)
From source file:projetohorus.TamanhoHost.java
void TamanhoHost() throws UnknownHostException, SocketException { InetAddress localHost = Inet4Address.getLocalHost(); NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost); short x = networkInterface.getInterfaceAddresses().get(0).getNetworkPrefixLength(); String n = localHost.getHostAddress() + "/" + x; System.out.println(n);/* w w w . j av a2 s . c om*/ SubnetUtils utils = new SubnetUtils(n); System.out.println(utils.getInfo()); String first = utils.getInfo().getLowAddress(); String last = utils.getInfo().getHighAddress(); String[] iplast = last.split(Pattern.quote(".")); String[] ipfirst = first.split(Pattern.quote(".")); numfirst = Integer.parseInt(ipfirst[3]); numlast = Integer.parseInt(iplast[3]); }
From source file:vn.vnpttech.ssdc.nms.webapp.util.SubnetUtil.java
/** * check ip range of two cidr is overlap * * @param cidr1// w w w. java 2 s .c o m * @param cidr2 * @return true if overlap, false if not */ public static boolean checkCidrOverlap(String cidr1, String cidr2) { SubnetUtils su = new SubnetUtils(cidr1); SubnetUtils su2 = new SubnetUtils(cidr2); int start1 = su.getInfo().asInteger(su.getInfo().getLowAddress()); int end1 = su.getInfo().asInteger(su.getInfo().getHighAddress()); int start2 = su2.getInfo().asInteger(su2.getInfo().getLowAddress()); int end2 = su2.getInfo().asInteger(su2.getInfo().getHighAddress()); boolean ret = false; if (!((end2 <= start1) && (end1 <= start2))) { ret = true; } else { ret = false; } return ret; }
From source file:vn.vnpttech.ssdc.nms.webapp.util.SubnetUtil.java
/** * Check ip range of cidr2 in ip range cidr1 * * @param cidr1// w w w .j a v a 2 s. c om * @param cidr2 * @return true if cidr2 in cidr1, false if not */ public static boolean checkCidrInCdir(String cidr1, String cidr2) { SubnetUtils su = new SubnetUtils(cidr1); SubnetUtils su2 = new SubnetUtils(cidr2); System.out.println(su.getInfo().getCidrSignature()); System.out.println(su.getInfo().getLowAddress()); System.out.println(su.getInfo().getHighAddress()); int end1 = su.getInfo().asInteger(su.getInfo().getHighAddress()); int start1 = su.getInfo().asInteger(su.getInfo().getLowAddress()); int end2 = su2.getInfo().asInteger(su2.getInfo().getHighAddress()); int start2 = su2.getInfo().asInteger(su2.getInfo().getLowAddress()); boolean ret = false; if ((start1 <= start2) && (end2 <= end1)) { ret = true; } else { ret = false; } return ret; }