List of utility methods to do Network Interface Get
String | getNetworkInterface() get Network Interface String networkInterfaceName = ">>>> modify networkInterface in us.codecraft.webmagic.utils.ProxyUtils"; Enumeration<NetworkInterface> enumeration = null; try { enumeration = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e1) { e1.printStackTrace(); while (enumeration.hasMoreElements()) { ... |
NetworkInterface | getNetworkInterface() get Network Interface try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); if (interfaces != null) { while (interfaces.hasMoreElements()) { try { return interfaces.nextElement(); } catch (Throwable e) { } catch (SocketException e) { return null; |
NetworkInterface | getNetworkInterface(String name) Method that searches for and returns the network interface having the specified name .
NetworkInterface nic = NetworkInterface.getByName(name); if (nic == null) { InetAddress targetIp = null; try { targetIp = InetAddress.getByName(name); nic = NetworkInterface.getByInetAddress(targetIp); } catch (UnknownHostException uhe) { return nic; |
NetworkInterface[] | getNetworkInterfaceArray(String name) Method that searches for and returns an array whose elements are all the network interface(s) that correspond to the specified name .
NetworkInterface[] nics = null; if (name.equals("all")) { Enumeration en = NetworkInterface.getNetworkInterfaces(); List nicList = (en != null) ? Collections.list(en) : Collections.EMPTY_LIST; nics = (NetworkInterface[]) (nicList.toArray(new NetworkInterface[nicList.size()])); } else { nics = new NetworkInterface[1]; nics[0] = NetworkInterface.getByName(name); ... |
NetworkInterface | getNetworkinterfaceByName(String name) get Networkinterface By Name Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface ni = networkInterfaces.nextElement(); if (ni.getName().equals(name)) { return ni; throw new SocketException("Interface with name '" + name + "' not found."); ... |
String | getNetworkInterfaceInfo(NetworkInterface pNif) get Network Interface Info if (pNif == null) { return "[null]"; return pNif.getDisplayName() + " [up: " + pNif.isUp() + ", mc: " + pNif.supportsMulticast() + ", lb: " + pNif.isLoopback() + ", hw: " + formatHwAddress(pNif.getHardwareAddress()) + "]"; |
List | getNetworkInterfaces(Predicate super NetworkInterface> predicate) Obtains the list of NetworkInterface s (of the machine on which this code is executing), ordered by NetworkInterface#getIndex() , that satisfy the specified Predicate . ArrayList<NetworkInterface> networkInterfaces = new ArrayList<>(); try { Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces(); while (enumeration.hasMoreElements()) { NetworkInterface networkInterface = enumeration.nextElement(); if (predicate.test(networkInterface)) { networkInterfaces.add(networkInterface); Collections.sort(networkInterfaces, new Comparator<NetworkInterface>() { @Override public int compare(NetworkInterface networkInterface1, NetworkInterface networkInterface2) { return networkInterface1.getIndex() - networkInterface2.getIndex(); }); } catch (SocketException e) { return networkInterfaces; |
List | getNetworkInterfaces() Gets all network interfaces of the localhost. List<NetworkInterface> niList = new ArrayList<NetworkInterface>(); for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); niList.add(intf); return niList; |
Collection | getNetworkInterfaces() Returns all network interfaces of this host. ArrayList<NetworkInterface> result = new ArrayList<NetworkInterface>(); Enumeration<NetworkInterface> ifs = null; try { ifs = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e1) { throw new IllegalStateException("Could not enumerate network interfaces!"); while (ifs.hasMoreElements()) { ... |
List | getNetworkInterfaces() get Network Interfaces try { return Collections.list(NetworkInterface.getNetworkInterfaces()); } catch (SocketException se) { se.printStackTrace(); return null; |