Get the Maximum Transmission Unit (MTU) of network in Java

Description

The following code shows how to get the Maximum Transmission Unit (MTU) of network.

Example


import java.net.NetworkInterface;
import java.util.Enumeration;
/*from w ww . j a  va  2  s .  c  om*/
public class Main {
  public static void main(String[] args) throws Exception {
    Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
    while (en.hasMoreElements()) {
      NetworkInterface ni = en.nextElement();
      System.out.println(" Display Name = " + ni.getDisplayName());
      System.out.println(" MTU = " + ni.getMTU());
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Network »




NetworkInterface
URI
URL
HTTP
HTTP Read
IP
Socket
UDP
URL Encode