Java Network Interface Get parseInterfaceList(String s)

Here you can find the source of parseInterfaceList(String s)

Description

parse Interface List

License

LGPL

Parameter

Parameter Description
s a parameter

Return

List

Declaration

public static List<NetworkInterface> parseInterfaceList(String s) throws Exception 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.net.*;

import java.util.*;

public class Main {
    /**/*  w  w  w. ja v a2s  . com*/
     *
     * @param s
     * @return List<NetworkInterface>
     */
    public static List<NetworkInterface> parseInterfaceList(String s) throws Exception {
        List<NetworkInterface> interfaces = new ArrayList<NetworkInterface>(10);
        if (s == null)
            return null;

        StringTokenizer tok = new StringTokenizer(s, ",");
        String interface_name;
        NetworkInterface intf;

        while (tok.hasMoreTokens()) {
            interface_name = tok.nextToken();

            // try by name first (e.g. (eth0")
            intf = NetworkInterface.getByName(interface_name);

            // next try by IP address or symbolic name
            if (intf == null)
                intf = NetworkInterface.getByInetAddress(InetAddress.getByName(interface_name));

            if (intf == null)
                throw new Exception("interface " + interface_name + " not found");
            if (!interfaces.contains(intf)) {
                interfaces.add(intf);
            }
        }
        return interfaces;
    }
}

Related

  1. getNonLoopbackNetworkInterface()
  2. getPublicInterface()
  3. getUsualNetworkInterfaces()
  4. isActive(String niName)
  5. isNixMashPC()
  6. pingFromInterface(String name)
  7. print(Collection objs)
  8. printValidInterfaces(PrintWriter pout)
  9. toNI(String niName)