集册 Java实例教程 按列表获取Inet地址

按列表获取Inet地址

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

461
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
按列表获取Inet地址
/**
n o w j a v a . c o m
**/


//package com.nowjava;

import java.net.InetAddress;

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(getInetAddressByList());/*时代Java公众号 提供*/

    }


    public static List<InetAddress> getInetAddressByList()

            throws SocketException {

        List<InetAddress> list = new ArrayList<InetAddress>();

        Enumeration<NetworkInterface> enumeration = NetworkInterface

                .getNetworkInterfaces();

        while (enumeration.hasMoreElements()) {

            NetworkInterface networkInterface = enumeration.nextElement();

            Enumeration<InetAddress> enumerationInetAddress = networkInterface

   
展开阅读全文