Here you can find the source of parseInterfaceList(String s)
Parameter | Description |
---|---|
s | a parameter |
public static List<NetworkInterface> parseInterfaceList(String s) throws Exception
//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; } }