Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.StringTokenizer; public class Main { public static boolean isInRange(String ip, String[] netInfo) { // Log.d(TAG, "checking if " + ip + " is in range of " + netInfo[0] + // "/" // + netInfo[1]); StringTokenizer maskTokens = new StringTokenizer(netInfo[1], "."); StringTokenizer ipTokens = new StringTokenizer(ip, "."); int ipArray[] = new int[4]; ipArray[0] = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken()); ipArray[1] = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken()); ipArray[2] = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken()); ipArray[3] = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken()); String networkAddress = ipArray[0] + "." + ipArray[1] + "." + ipArray[2] + "." + ipArray[3]; return netInfo[0].equals(networkAddress); } }