List of usage examples for java.net NetworkInterface isPointToPoint
public boolean isPointToPoint() throws SocketException
From source file:org.springframework.data.hadoop.util.net.DefaultHostInfoDiscovery.java
private List<NetworkInterface> filterInterfaces(List<NetworkInterface> interfaces) { List<NetworkInterface> filtered = new ArrayList<NetworkInterface>(); for (NetworkInterface nic : interfaces) { boolean match = false; try {/* www . ja v a 2 s .c o m*/ match = pointToPoint && nic.isPointToPoint(); } catch (SocketException e) { } try { match = !match && loopback && nic.isLoopback(); } catch (SocketException e) { } // last, if we didn't match anything, let all pass // if matchInterface is not set, otherwise do pattern // matching if (!match && !StringUtils.hasText(matchInterface)) { match = true; } else if (StringUtils.hasText(matchInterface)) { match = nic.getName().matches(matchInterface); } if (match) { filtered.add(nic); } } return filtered; }
From source file:net.mm2d.dmsexplorer.ServerListActivity.java
private Collection<NetworkInterface> getWifiInterface() { final NetworkInfo ni = mConnectivityManager.getActiveNetworkInfo(); if (ni == null || !ni.isConnected() || ni.getType() != ConnectivityManager.TYPE_WIFI) { return null; }//w w w . jav a2s .c om final InetAddress address = getWifiInetAddress(); if (address == null) { return null; } final Enumeration<NetworkInterface> nis; try { nis = NetworkInterface.getNetworkInterfaces(); } catch (final SocketException e) { return null; } while (nis.hasMoreElements()) { final NetworkInterface nif = nis.nextElement(); try { if (nif.isLoopback() || nif.isPointToPoint() || nif.isVirtual() || !nif.isUp()) { continue; } final List<InterfaceAddress> ifas = nif.getInterfaceAddresses(); for (final InterfaceAddress a : ifas) { if (a.getAddress().equals(address)) { final Collection<NetworkInterface> c = new ArrayList<>(); c.add(nif); return c; } } } catch (final SocketException ignored) { } } return null; }
From source file:fr.inria.ucn.collectors.NetworkStateCollector.java
private JSONArray getIfconfig(Map<String, JSONObject> stats) throws JSONException { JSONArray ifaces = new JSONArray(); // make sure the stats is read networkStats();//from w ww . j a v a 2 s . c o m Enumeration<NetworkInterface> en = null; try { en = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { Log.d(Constants.LOGTAG, "failed to list interfaces", e); } if (en != null) { while (en.hasMoreElements()) { NetworkInterface intf = en.nextElement(); JSONObject iface = new JSONObject(); iface.put("display_name", intf.getDisplayName()); iface.put("name", intf.getName()); iface.put("is_virtual", intf.isVirtual()); iface.put("stats", stats.get(intf.getName())); try { iface.put("mtu", intf.getMTU()); iface.put("is_loopback", intf.isLoopback()); iface.put("is_ptop", intf.isPointToPoint()); iface.put("is_up", intf.isUp()); } catch (SocketException e) { Log.d(Constants.LOGTAG, "failed to read interface data", e); } JSONArray ips = new JSONArray(); List<InterfaceAddress> ilist = intf.getInterfaceAddresses(); for (InterfaceAddress ia : ilist) { ips.put(ia.getAddress().getHostAddress()); } iface.put("addresses", ips); ifaces.put(iface); } } else { for (String name : stats.keySet()) { JSONObject iface = new JSONObject(); iface.put("name", name); iface.put("stats", stats.get(name)); ifaces.put(iface); } } return ifaces; }
From source file:org.wso2.carbon.appmanager.integration.ui.APPManagerIntegrationTest.java
protected String getNetworkIPAddress() { String networkIpAddress = null; try {//from w w w .j a v a2 s . co m String localhost = InetAddress.getLocalHost().getHostAddress(); Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); while (e.hasMoreElements()) { NetworkInterface ni = (NetworkInterface) e.nextElement(); if (ni.isLoopback()) continue; if (ni.isPointToPoint()) continue; Enumeration<InetAddress> addresses = ni.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = (InetAddress) addresses.nextElement(); if (address instanceof Inet4Address) { String ip = address.getHostAddress(); if (!ip.equals(localhost)) { networkIpAddress = ip; } } } } } catch (UnknownHostException e) { log.error("Error occurred due to an unknown host.", e); } catch (SocketException e) { log.error("Error occurred with Socket connections", e); } return networkIpAddress; }