Package java.net

Examples of java.net.InterfaceAddress


      }).start();
    }
  }

  private InterfaceAddress getPreferredInetAddress(String prefix) {
    InterfaceAddress selectedInterfaceAddress = null;
    try {
      Enumeration<NetworkInterface> list = NetworkInterface.getNetworkInterfaces();

      while (list.hasMoreElements()) {
        NetworkInterface iface = list.nextElement();
        if (iface == null)
          continue;
        Log.d(LOG_TAG, "interface=" + iface.getName());
        Iterator<InterfaceAddress> it = iface.getInterfaceAddresses().iterator();
        while (it.hasNext()) {
          InterfaceAddress interfaceAddress = it.next();
          if (interfaceAddress == null)
            continue;
          InetAddress address = interfaceAddress.getAddress();
          Log.d(LOG_TAG, "address=" + address);
          if (address instanceof Inet4Address) {
            // Only pick an interface that is likely to be on the
            // same subnet as the selected ChromeCast device
            if (address.getHostAddress().toString().startsWith(prefix)) {
View Full Code Here


   * @return
   */
  public Inet4Address getNetworAddress() {
    Inet4Address selectedInetAddress = null;
    try {
      InterfaceAddress interfaceAddress = null;
      if (selectedDialServer != null) {
        String address = selectedDialServer.getIpAddress().getHostAddress();
        String prefix = address.substring(0, address.indexOf('.') + 1);
        Log.d(LOG_TAG, "prefix=" + prefix);
        interfaceAddress = getPreferredInetAddress(prefix);
      } else {
        InterfaceAddress oneNineTwoInetAddress = getPreferredInetAddress("192.");
        if (oneNineTwoInetAddress != null) {
          interfaceAddress = oneNineTwoInetAddress;
        } else {
          InterfaceAddress oneSevenTwoInetAddress = getPreferredInetAddress("172.");
          if (oneSevenTwoInetAddress != null) {
            interfaceAddress = oneSevenTwoInetAddress;
          } else {
            interfaceAddress = getPreferredInetAddress("10.");
          }
View Full Code Here

TOP

Related Classes of java.net.InterfaceAddress

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.