Package java.net

Examples of java.net.InterfaceAddress


    public static String[] getNetworkParams(NetworkInterface nic) {
        List<InterfaceAddress> addrs = nic.getInterfaceAddresses();
        if (addrs == null || addrs.size() == 0) {
            return null;
        }
        InterfaceAddress addr = null;
        for (InterfaceAddress iaddr : addrs) {
            InetAddress inet = iaddr.getAddress();
            if (!inet.isLinkLocalAddress() && !inet.isLoopbackAddress() && !inet.isMulticastAddress() && inet.getAddress().length == 4) {
                addr = iaddr;
                break;
            }
        }
        if (addr == null) {
            return null;
        }
        String[] result = new String[3];
        result[0] = addr.getAddress().getHostAddress();
        try {
            byte[] mac = nic.getHardwareAddress();
            result[1] = byte2Mac(mac);
        } catch (Exception e) {
        }

        result[2] = prefix2Netmask(addr.getNetworkPrefixLength());
        return result;
    }
View Full Code Here


    public static String[] getNetworkParams(NetworkInterface nic) {
        List<InterfaceAddress> addrs = nic.getInterfaceAddresses();
        if (addrs == null || addrs.size() == 0) {
            return null;
        }
        InterfaceAddress addr = null;
        for (InterfaceAddress iaddr : addrs) {
            InetAddress inet = iaddr.getAddress();
            if (!inet.isLinkLocalAddress() && !inet.isLoopbackAddress() && !inet.isMulticastAddress() && inet.getAddress().length == 4) {
                addr = iaddr;
                break;
            }
        }
        if (addr == null) {
            return null;
        }
        String[] result = new String[3];
        result[0] = addr.getAddress().getHostAddress();
        try {
            byte[] mac = nic.getHardwareAddress();
            result[1] = byte2Mac(mac);
        } catch (Exception e) {
        }

        result[2] = prefix2Netmask(addr.getNetworkPrefixLength());
        return result;
    }
View Full Code Here

    public static String[] getNetworkParams(NetworkInterface nic) {
        List<InterfaceAddress> addrs = nic.getInterfaceAddresses();
        if (addrs == null || addrs.size() == 0) {
            return null;
        }
        InterfaceAddress addr = null;
        for (InterfaceAddress iaddr : addrs) {
            InetAddress inet = iaddr.getAddress();
            if (!inet.isLinkLocalAddress() && !inet.isLoopbackAddress() && !inet.isMulticastAddress() && inet.getAddress().length == 4) {
                addr = iaddr;
                break;
            }
        }
        if (addr == null) {
            return null;
        }
        String[] result = new String[3];
        result[0] = addr.getAddress().getHostAddress();
        try {
            byte[] mac = nic.getHardwareAddress();
            result[1] = byte2Mac(mac);
        } catch (Exception e) {
        }

        result[2] = prefix2Netmask(addr.getNetworkPrefixLength());
        return result;
    }
View Full Code Here

    public static String[] getNetworkParams(NetworkInterface nic) {
        List<InterfaceAddress> addrs = nic.getInterfaceAddresses();
        if (addrs == null || addrs.size() == 0) {
            return null;
        }
        InterfaceAddress addr = null;
        for (InterfaceAddress iaddr : addrs) {
            InetAddress inet = iaddr.getAddress();
            if (!inet.isLinkLocalAddress() && !inet.isLoopbackAddress() && !inet.isMulticastAddress() && inet.getAddress().length == 4) {
                addr = iaddr;
                break;
            }
        }
        if (addr == null) {
            return null;
        }
        String[] result = new String[3];
        result[0] = addr.getAddress().getHostAddress();
        try {
            byte[] mac = nic.getHardwareAddress();
            result[1] = byte2Mac(mac);
        } catch (Exception e) {
        }

        result[2] = prefix2Netmask(addr.getNetworkPrefixLength());
        return result;
    }
View Full Code Here

    public static String[] getNetworkParams(NetworkInterface nic) {
        List<InterfaceAddress> addrs = nic.getInterfaceAddresses();
        if (addrs == null || addrs.size() == 0) {
            return null;
        }
        InterfaceAddress addr = null;
        for (InterfaceAddress iaddr : addrs) {
            InetAddress inet = iaddr.getAddress();
            if (!inet.isLinkLocalAddress() && !inet.isLoopbackAddress() && !inet.isMulticastAddress() && inet.getAddress().length == 4) {
                addr = iaddr;
                break;
            }
        }
        if (addr == null) {
            return null;
        }
        String[] result = new String[3];
        result[0] = addr.getAddress().getHostAddress();
        try {
            byte[] mac = nic.getHardwareAddress();
            result[1] = byte2Mac(mac);
        } catch (Exception e) {
        }

        result[2] = prefix2Netmask(addr.getNetworkPrefixLength());
        return result;
    }
View Full Code Here

            while (en.hasMoreElements()) {
                NetworkInterface ni = en.nextElement();
                List<InterfaceAddress> listIa = ni.getInterfaceAddresses();
                Iterator<InterfaceAddress> it = listIa.iterator();
                while (it.hasNext()) {
                    InterfaceAddress ia = it.next();
                    list.append(new Ifaddr(context.runtime, (RubyClass)context.runtime.getClassFromPath("Socket::Ifaddr"), ni, ia, true));
                    list.append(new Ifaddr(context.runtime, (RubyClass)context.runtime.getClassFromPath("Socket::Ifaddr"), ni, ia, false));
                }
            }
        } catch (Exception ex) {
View Full Code Here

  public FileInputStream openFileInput(String name) throws FileNotFoundException {
    return new FileInputStream(name);
  }

  private static 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(String dialServerAddress) {
    Inet4Address selectedInetAddress = null;
    try {
      InterfaceAddress interfaceAddress = null;
      if (dialServerAddress != null) {
        String prefix = dialServerAddress.substring(0, dialServerAddress.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

    public static String[] getNetworkParams(NetworkInterface nic) {
        List<InterfaceAddress> addrs = nic.getInterfaceAddresses();
        if (addrs == null || addrs.size() == 0) {
            return null;
        }
        InterfaceAddress addr = null;
        for (InterfaceAddress iaddr : addrs) {
            InetAddress inet = iaddr.getAddress();
            if (!inet.isLinkLocalAddress() && !inet.isLoopbackAddress() && !inet.isMulticastAddress() && inet.getAddress().length == 4) {
                addr = iaddr;
                break;
            }
        }
        if (addr == null) {
            return null;
        }
        String[] result = new String[3];
        result[0] = addr.getAddress().getHostAddress();
        try {
            byte[] mac = nic.getHardwareAddress();
            result[1] = byte2Mac(mac);
        } catch (Exception e) {
        }

        result[2] = prefix2Netmask(addr.getNetworkPrefixLength());
        return result;
    }
View Full Code Here

    public static String[] getNetworkParams(NetworkInterface nic) {
        List<InterfaceAddress> addrs = nic.getInterfaceAddresses();
        if (addrs == null || addrs.size() == 0) {
            return null;
        }
        InterfaceAddress addr = null;
        for (InterfaceAddress iaddr : addrs) {
            InetAddress inet = iaddr.getAddress();
            if (!inet.isLinkLocalAddress() && !inet.isLoopbackAddress() && !inet.isMulticastAddress() && inet.getAddress().length == 4) {
                addr = iaddr;
                break;
            }
        }
        if (addr == null) {
            return null;
        }
        String[] result = new String[3];
        result[0] = addr.getAddress().getHostAddress();
        try {
            byte[] mac = nic.getHardwareAddress();
            result[1] = byte2Mac(mac);
        } catch (Exception e) {
        }

        result[2] = prefix2Netmask(addr.getNetworkPrefixLength());
        return result;
    }
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.