Java tutorial
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; public class Main { /** * Calculates the network mask value from the address * * @param address * the network mask * @return */ public static int networkMaskFromInetAddress(InetAddress address) { byte[] addrs = address.getAddress(); int result = 0; int i = 24; for (byte value : addrs) { result += value << i; i -= 8; } return result; } }