public static int getMTU() {
        Enumeration<NetworkInterface> en = null;
        int minMTU = Integer.MAX_VALUE;
        try {
            en = NetworkInterface.getNetworkInterfaces();
            while (en.hasMoreElements()) {
                NetworkInterface ni = en.nextElement();
                int mtu = ni.getMTU();
                if (mtu != -1 && mtu < minMTU)
                    minMTU = mtu;
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
        return minMTU;
    }