集册 Java实例教程 获取网络接口列表

获取网络接口列表

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

491
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取网络接口列表


//package com.nowjava;/*NowJava.com - 时代Java*/

import java.net.NetworkInterface;

import java.net.SocketException;

import java.util.ArrayList;

import java.util.Enumeration;

import java.util.List;


public class Main {

    public static void main(String[] argv) throws Exception {

        System.out.println(getNetworkInterfaceList());

    }
/*from n o w j a v a . c o m*/

    public static List<NetworkInterface> getNetworkInterfaceList() {

        List<NetworkInterface> networkInterfaceList = new ArrayList<NetworkInterface>();

        try {

            for (Enumeration<NetworkInterface> interfaces = NetworkInterface

                    .getNetworkInterfaces(); interfaces.hasMoreElements();) {

                NetworkInterface networkInterface = interfaces

                        .nextElement();

                if ((networkInterface.isLoopback())

                        || (networkInterface.isVirtual())

                        || (!networkInterface.isUp())

                        || (networkInterface.isPointToPoint()))

                    
展开阅读全文