// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Collections;
import java.util.Enumeration;

public class IPMatch2 {
    private static boolean check(String val) throws IOException {
        Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
        for (NetworkInterface nic : Collections.list(nics)) {
            Enumeration<InetAddress> nicaddrs = nic.getInetAddresses();
            for (InetAddress nicaddr : Collections.list(nicaddrs)) {
                if(nicaddr.toString().substring(1).startsWith(val)) {
                    return true;
                }
            }
        }
        return false;
    }
    public static void main(String[] args) throws Exception {
        System.out.println(check("172.16.0"));
        System.out.println(check("10.10.0"));
        System.out.println(check("192.168.0"));
        System.out.println(check("172.27.20"));
    }
}
