public static void main(String[] args) throws PcapNativeException, NotOpenException { PcapNetworkInterface nif; try { nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
/** * @return a PcapNetworkInterface object which represents a selected network interface. * @throws IOException if no network interface is available. */ public final PcapNetworkInterface selectNetworkInterface() throws IOException { List<PcapNetworkInterface> allDevs = null; try { allDevs = Pcaps.findAllDevs(); } catch (PcapNativeException e) { throw new IOException(e.getMessage()); } if (allDevs == null || allDevs.isEmpty()) { throw new IOException("No NIF to capture."); } showNifList(allDevs); return doSelect(allDevs); }
int nifIdx; while (true) { write("Select a device number to capture packets, or enter 'q' to quit > "); if ((input = read()) == null) { continue; nifIdx = Integer.parseInt(input); if (nifIdx < 0 || nifIdx >= nifs.size()) { write("Invalid input." + LINE_SEPARATOR); continue; } else { write("Invalid input." + LINE_SEPARATOR); continue;
/** * @param nifs nifs * @throws IOException if fails to show. */ protected void showNifList(List<PcapNetworkInterface> nifs) throws IOException { StringBuilder sb = new StringBuilder(200); int nifIdx = 0; for (PcapNetworkInterface nif : nifs) { sb.append("NIF[").append(nifIdx).append("]: ").append(nif.getName()).append(LINE_SEPARATOR); if (nif.getDescription() != null) { sb.append(" : description: ").append(nif.getDescription()).append(LINE_SEPARATOR); } for (LinkLayerAddress addr : nif.getLinkLayerAddresses()) { sb.append(" : link layer address: ").append(addr).append(LINE_SEPARATOR); } for (PcapAddress addr : nif.getAddresses()) { sb.append(" : address: ").append(addr.getAddress()).append(LINE_SEPARATOR); } nifIdx++; } sb.append(LINE_SEPARATOR); write(sb.toString()); }
/** * @param nifs nifs * @throws IOException if fails to show. */ protected void showNifList(List<PcapNetworkInterface> nifs) throws IOException { StringBuilder sb = new StringBuilder(200); int nifIdx = 0; for (PcapNetworkInterface nif : nifs) { sb.append("NIF[").append(nifIdx).append("]: ").append(nif.getName()).append(LINE_SEPARATOR); if (nif.getDescription() != null) { sb.append(" : description: ").append(nif.getDescription()).append(LINE_SEPARATOR); } for (LinkLayerAddress addr : nif.getLinkLayerAddresses()) { sb.append(" : link layer address: ").append(addr).append(LINE_SEPARATOR); } for (PcapAddress addr : nif.getAddresses()) { sb.append(" : address: ").append(addr.getAddress()).append(LINE_SEPARATOR); } nifIdx++; } sb.append(LINE_SEPARATOR); write(sb.toString()); }
nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
/** * @return a PcapNetworkInterface object which represents a selected network interface. * @throws IOException if no network interface is available. */ public final PcapNetworkInterface selectNetworkInterface() throws IOException { List<PcapNetworkInterface> allDevs = null; try { allDevs = Pcaps.findAllDevs(); } catch (PcapNativeException e) { throw new IOException(e.getMessage()); } if (allDevs == null || allDevs.isEmpty()) { throw new IOException("No NIF to capture."); } showNifList(allDevs); return doSelect(allDevs); }
int nifIdx; while (true) { write("Select a device number to capture packets, or enter 'q' to quit > "); if ((input = read()) == null) { continue; nifIdx = Integer.parseInt(input); if (nifIdx < 0 || nifIdx >= nifs.size()) { write("Invalid input." + LINE_SEPARATOR); continue; } else { write("Invalid input." + LINE_SEPARATOR); continue;
nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
} else { try { nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
} else { try { nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
public static void main(String[] args) throws PcapNativeException, NotOpenException { PcapNetworkInterface nif; try { nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();
nif = new NifSelector().selectNetworkInterface(); } catch (IOException e) { e.printStackTrace();