Here you can find the source of isInRage(InetAddress check, InetAddress bcast, int netmask)
public static boolean isInRage(InetAddress check, InetAddress bcast, int netmask)
//package com.java2s; //License from project: LGPL import java.net.InetAddress; public class Main { public static boolean isInRage(InetAddress check, InetAddress bcast, int netmask) { //System.out.println("*** check " + check + " in " + bcast + "/" + netmask); int byts = netmask / 8; // netmask%8 are the remaining bits. The mask is for the upper bits of the remaining byte byte mask = (byte) ~(0xff >>> (netmask % 8)); byte[] b1 = check.getAddress(); byte[] b2 = bcast.getAddress(); int i;//from www . jav a2s.c om for (i = 0; i < byts; i++) { if (b1[i] != b2[i]) { return false; } } // remaining bits if (mask != 0 && (b1[i] & mask) != (b2[i] & mask)) { return false; } return true; } }