集册 Java实例教程 列出扩展网络接口

列出扩展网络接口

欢马劈雪     最近更新时间:2020-01-02 10:19:05

516
列出扩展网络接口

import java.io.*;

import java.net.*;
/**
 from
* N o w  J a v a  . c o m 
**/

import java.util.*;

import static java.lang.System.out;


public class ListNetsEx {


    public static void main(String args[]) throws SocketException {

        Enumeration<NetworkInterface> nets = NetworkInterface

                .getNetworkInterfaces();

        for (NetworkInterface netint : Collections.list(nets))

            displayInterfaceInformation(netint);

    }


    static void displayInterfaceInformation(NetworkInterface netint)

            throws SocketException {

        out.printf("Display name: %s\n", netint.getDisplayName());

        out.printf("Name: %s\n", netint.getName());

        Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
        /*
         from N o w  J a v a  . c o m 
        */


        for (InetAddress inetAddress : Collections.list(inetAddresses)) {

            out.printf("InetAddress: %s\n", inetAddress);

        }


        out.printf("Up? %s\n", netint.isUp());

        out.printf("Loopback? %s\n", netint.isLoopback());

        out.printf("PointToPoint? %s\n", netint.isPointToPoint());

        out.printf("Supports multicast? %s\n", netint.supportsMulticast());

        out.printf("Virtual? %s\n", netint.isVirtual());

        out.printf("Hardware address: %s\n",

                Arrays.toString(netint.getHardwareAddress()));

        out.printf("MTU: %s\n", netint.getMTU());

        out.printf("\n");

    }

}


展开阅读全文