class NetUtils {

    public static InetAddress getSubnetPrefix(InetAddress ip, int maskLen) {
        int bytes = maskLen / 8;
        int bits = maskLen % 8;
        byte modifiedByte;
        byte[] sn = ip.getAddress();
        if (bits > 0) {
            modifiedByte = (byte) (sn[bytes] >> 8 - bits);
            sn[bytes] = (byte) (modifiedByte << 8 - bits);
            bytes++;
        }
        for (; bytes < sn.length; bytes++) {
            sn[bytes] = (byte) 0;
        }
        try {
            return InetAddress.getByAddress(sn);
        } catch (UnknownHostException e) {
            return null;
        }
    }

    private  NetUtils();

}