1 19 20 package com.sslexplorer.core; 21 22 import java.net.InetAddress ; 23 import java.net.NetworkInterface ; 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.Enumeration ; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.struts.util.LabelValueBean; 31 32 import com.sslexplorer.input.MultiSelectDataSource; 33 import com.sslexplorer.security.SessionInfo; 34 35 41 42 public class InterfacesMultiSelectListDataSource implements MultiSelectDataSource { 43 44 final static Log log = LogFactory.getLog(InterfacesMultiSelectListDataSource.class); 45 46 47 50 public Collection <LabelValueBean> getValues(SessionInfo session) { 51 ArrayList l = new ArrayList (); 52 try { 53 l.add(new LabelValueBean("All Interfaces", 55 "0.0.0.0")); 56 for(Enumeration e = NetworkInterface.getNetworkInterfaces(); 57 e.hasMoreElements(); ) { 58 NetworkInterface ni = (NetworkInterface )e.nextElement(); 59 for(Enumeration e2 = ni.getInetAddresses(); e2.hasMoreElements(); ) { 60 InetAddress addr = (InetAddress )e2.nextElement(); 61 l.add(new LabelValueBean(addr.getHostAddress(), 62 addr.getHostAddress())); 63 } 64 } 65 } 66 catch(Throwable t) { 67 log.error("Failed to list network interfaces.", t); 68 } 69 return l; 70 } 71 } 72 | Popular Tags |