questo è l'output di ifconfig:
da questo output io vorrei estrapolare solo il nome (lo0, gif0,stf0,....) e poi riempirci un arraylist.codice:lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 inet 127.0.0.1 netmask 0xff000000 gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280 stf0: flags=0<> mtu 1280 en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether 34:15:9e:15:8a:38 media: autoselect status: inactive en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether 58:b0:35:63:0d:e9 inet6 fe80::5ab0:35ff:fe63:de9%en1 prefixlen 64 scopeid 0x5 inet 10.0.1.5 netmask 0xffffff00 broadcast 10.0.1.255 media: autoselect status: active
il problema è che tutto l'ouput viene considerato insieme.codice:public static void discover() throws IOException { ArrayList<String> list = new ArrayList<String>(); Process p = Runtime.getRuntime().exec("ifconfig"); InputStream input = p.getInputStream(); InputStreamReader reader = new InputStreamReader(input); BufferedReader br = new BufferedReader(reader); String line; while ((line = br.readLine()) != null) { // System.out.println(line); list.add(line); } for (Object obj : list) { System.out.println(list); } br.close(); reader.close(); input.close(); }
in sostanza line è tutto l'output del comando.
come posso fare per spezzarlo prendendo solo determinate parti??

Rispondi quotando