Package java.net

Examples of java.net.NetworkInterface


                final int groupPort = CommonAttributes.GROUP_PORT.resolveModelAttribute(context, model).asInt();

                try {

                    final InetAddress inet = localAddress != null ? InetAddress.getByName(localAddress) : InetAddressUtil.getLocalHost();
                    final NetworkInterface intf = NetworkInterface.getByInetAddress(inet);
                    final NetworkInterfaceBinding b = new NetworkInterfaceBinding(Collections.singleton(intf), inet);
                    final InetAddress group = InetAddress.getByName(groupAddress);

                    final SocketBinding socketBinding = new SocketBinding(name, -1, false, group, groupPort, b, null, null);
View Full Code Here


    private boolean isLocal() {
        try {
            String hostName = uri.getHost();
            InetAddress address = InetAddress.getByName(hostName);
            NetworkInterface nic = NetworkInterface.getByInetAddress(address);

            return address.isLoopbackAddress() || nic != null;
        } catch (Exception e) {
            return false;
        }
View Full Code Here

                        .getNetworkInterfaces();
                while (netInterfaces.hasMoreElements()) {
                    if (bFindIP) {
                        break;
                    }
                    NetworkInterface ni = netInterfaces
                            .nextElement();
                    // ----------特定情况,可以考虑用ni.getName判断
                    // 遍历所有ip
                    Enumeration<InetAddress> ips = ni.getInetAddresses();
                    while (ips.hasMoreElements()) {
                        ip = ips.nextElement();
                        if (ip.isSiteLocalAddress() && !ip.isLoopbackAddress() // 127.开头的都是lookback地址
                                && !ip.getHostAddress().contains(":")) {
                            bFindIP = true;
View Full Code Here

        try {
            ArrayList<String> list = new ArrayList<String>();
            Enumeration<NetworkInterface> e = NetworkInterface
                    .getNetworkInterfaces();
            while (e.hasMoreElements()) {
                NetworkInterface ni = e.nextElement();
                byte[] mac = ni.getHardwareAddress();
                if (mac != null) {
                    String x = StringUtils.convertBytesToHex(mac);
                    list.add(x);
                }
            }
View Full Code Here

    public InterfacesTest() throws IOException {
        // Retrieve an address of some remote network interface
        Enumeration<NetworkInterface> interfaces =  NetworkInterface.getNetworkInterfaces();
       
        while (remoteInterfaceAddress == null && interfaces.hasMoreElements()) {
            NetworkInterface interfaze = interfaces.nextElement();
            Enumeration<InetAddress> addresses =  interfaze.getInetAddresses();
            if (addresses.hasMoreElements()) {
                InetAddress nextAddress = addresses.nextElement();
                if (nextAddress.isLoopbackAddress() || !nextAddress.isReachable(2000)) {
                    continue;
                }
View Full Code Here

   * @tests java.net.Inet6Address#getByAddress(String, byte[],
   *        NetworkInterface)
   */
  public void test_getByAddressLString$BLNetworkInterface()
      throws UnknownHostException {
    NetworkInterface nif = null;
    try {
      Inet6Address.getByAddress("123", null, nif);
      fail("should throw UnknownHostException");
    } catch (UnknownHostException uhe) {
      // expected
View Full Code Here

        assertFalse(ia.isReachable(null, 0, 1000));

        // Regression test for HARMONY-1842.
        ia = InetAddress.getByName("localhost"); //$NON-NLS-1$
        Enumeration<NetworkInterface> nif = NetworkInterface.getNetworkInterfaces();
        NetworkInterface netif;
        while(nif.hasMoreElements()) {
            netif = nif.nextElement();
            ia.isReachable(netif, 10, 1000);
        }
    }
View Full Code Here

    // Regression Test for Harmony-2290
    public void test_isReachableLjava_net_NetworkInterfaceII_loopbackInterface() throws IOException {
        final int TTL = 20;
        final int TIME_OUT = 3000;
       
        NetworkInterface loopbackInterface = null;
        ArrayList<InetAddress> localAddresses = new ArrayList<InetAddress>();
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
                .getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            NetworkInterface networkInterface = networkInterfaces.nextElement();
            Enumeration<InetAddress> addresses = networkInterface
                    .getInetAddresses();
            while (addresses.hasMoreElements()) {
                InetAddress address = addresses.nextElement();
                if (address.isLoopbackAddress()) {
                    loopbackInterface = networkInterface;
View Full Code Here

    // bound to it. For these tests only work with NetworkInterface objects
    // that are bound to an InetAddress.  
    if ((theInterfaces != null) && (theInterfaces.hasMoreElements())) {
      while ((theInterfaces.hasMoreElements())
          && (atLeastOneInterface == false)) {
        NetworkInterface theInterface = (NetworkInterface) theInterfaces
            .nextElement();
        if (theInterface.getInetAddresses() != null) {
          // Ensure that the current NetworkInterface has at least
          // one InetAddress bound to it. 
          Enumeration addrs = theInterface.getInetAddresses();
          if ((addrs != null) && (addrs.hasMoreElements())) {
            atLeastOneInterface = true;
            networkInterface1 = theInterface;
          }// end if
        }
      }

      while ((theInterfaces.hasMoreElements())
          && (atLeastTwoInterfaces == false)) {
        NetworkInterface theInterface = (NetworkInterface) theInterfaces
            .nextElement();
        if (theInterface.getInetAddresses() != null) {
          // Ensure that the current NetworkInterface has at least
          // one InetAddress bound to it. 
          Enumeration addrs = theInterface.getInetAddresses();
          if ((addrs != null) && (addrs.hasMoreElements())) {
            atLeastTwoInterfaces = true;
            networkInterface2 = theInterface;
          }// end if
        }
View Full Code Here

    int groupPort = Support_PortManager.getNextPortForUDP();
    if (atLeastOneInterface) {
            // validate that we get the expected response when one was not
            // set
            mss = new MulticastSocket(groupPort);
            NetworkInterface theInterface = mss.getNetworkInterface();
            assertNotNull(
                    "network interface returned wrong network interface when not set:"
                            + theInterface, theInterface.getInetAddresses());
            InetAddress firstAddress = (InetAddress) theInterface
                    .getInetAddresses().nextElement();
            // validate we the first address in the network interface is the
            // ANY address
            String preferIPv4StackValue = System
                    .getProperty("java.net.preferIPv4Stack");
View Full Code Here

TOP

Related Classes of java.net.NetworkInterface

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.