Package java.net

Examples of java.net.NetworkInterface


            // if there is more than one network interface then check that
            // we can join on specific interfaces and that we only receive
            // if data is received on that interface
            if (atLeastTwoInterfaces) {
                // set up server on first interfaces
                NetworkInterface loopbackInterface = NetworkInterface
                        .getByInetAddress(InetAddress.getByName("127.0.0.1"));

                theInterfaces = NetworkInterface.getNetworkInterfaces();
                while (theInterfaces.hasMoreElements()) {

                    NetworkInterface thisInterface = (NetworkInterface) theInterfaces
                            .nextElement();
                    if ((thisInterface.getInetAddresses() != null && thisInterface
                            .getInetAddresses().hasMoreElements())
                            && (Support_NetworkInterface
                                    .useInterface(thisInterface) == true)) {
                        // get the first address on the interface

                        // start server which is joined to the group and has
                        // only asked for packets on this interface
                        Enumeration addresses = thisInterface
                                .getInetAddresses();

                        NetworkInterface sendingInterface = null;
                        boolean isLoopback = false;
                        if (addresses != null) {
                            InetAddress firstAddress = (InetAddress) addresses
                                    .nextElement();
                            if (firstAddress.isLoopbackAddress()) {
                                isLoopback = true;
                            }
                            if (firstAddress instanceof Inet4Address) {
                                group = InetAddress.getByName("224.0.0.4");
                                if (networkInterface1.equals(NetworkInterface
                                        .getByInetAddress(InetAddress
                                                .getByName("127.0.0.1")))) {
                                    sendingInterface = networkInterface2;
                                } else {
                                    sendingInterface = networkInterface1;
                                }
                            } else {
                                // if this interface only seems to support
                                // IPV6 addresses
                                group = InetAddress
                                        .getByName("FF01:0:0:0:0:0:2:8001");
                                sendingInterface = IPV6networkInterface1;
                            }
                        }

                        InetAddress useAddress = null;
                        addresses = sendingInterface.getInetAddresses();
                        if ((addresses != null)
                                && (addresses.hasMoreElements())) {
                            useAddress = (InetAddress) addresses.nextElement();
                        }
View Full Code Here


            // set up the server and join the group
            group = InetAddress.getByName("224.0.0.3");

            Enumeration theInterfaces = NetworkInterface.getNetworkInterfaces();
            while (theInterfaces.hasMoreElements()) {
                NetworkInterface thisInterface = (NetworkInterface) theInterfaces
                        .nextElement();
                if (thisInterface.getInetAddresses() != null
                        && thisInterface.getInetAddresses().hasMoreElements()) {
                    if ((!((InetAddress) thisInterface.getInetAddresses()
                            .nextElement()).isLoopbackAddress())
                            &&
                            // for windows we cannot use these pseudo
                            // interfaces for the test as the packets still
                            // come from the actual interface, not the
                            // Pseudo interface that was set
                            (Support_NetworkInterface
                                    .useInterface(thisInterface) == true)) {
                        ports = Support_PortManager.getNextPortsForUDP(2);
                        serverPort = ports[0];
                        server = new MulticastServer(group, serverPort);
                        server.start();
                        // give the server some time to start up
                        Thread.sleep(1000);

                        // Send the packets on a particular interface. The
                        // source address in the received packet
                        // should be one of the addresses for the interface
                        // set
                        groupPort = ports[1];
                        mss = new MulticastSocket(groupPort);
                        mss.setNetworkInterface(thisInterface);
                        msg = thisInterface.getName();
                        byte theBytes[] = msg.getBytes();
                        DatagramPacket sdp = new DatagramPacket(theBytes,
                                theBytes.length, group, serverPort);
                        mss.send(sdp);
                        Thread.sleep(1000);
View Full Code Here

        theInterfaces = NetworkInterface.getNetworkInterfaces();
      } catch (Exception e) {
      }
      boolean found = false;
      while (theInterfaces.hasMoreElements() && !found) {
        NetworkInterface nextInterface = (NetworkInterface) theInterfaces
            .nextElement();
        addresses = nextInterface.getInetAddresses();
        if (addresses != null) {
          while (addresses.hasMoreElements()) {
            InetAddress nextAddress = (InetAddress) addresses
                .nextElement();
            if (nextAddress instanceof Inet6Address) {
View Full Code Here

        }
        try {
            InetAddress dest = InetAddress.getByName(hostname);
            Enumeration en = NetworkInterface.getNetworkInterfaces();
            while (en.hasMoreElements()) {
                NetworkInterface iface = (NetworkInterface) en.nextElement();
                Enumeration ine = iface.getInetAddresses();
                while (ine.hasMoreElements()) {
                    InetAddress address = (InetAddress) ine.nextElement();
                    if (address.equals(dest)) {
                        isSameMachine = true;
                    }
View Full Code Here

        }
        try {
            InetAddress dest = InetAddress.getByName(hostname);
            Enumeration en = NetworkInterface.getNetworkInterfaces();
            while (en.hasMoreElements()) {
                NetworkInterface iface = (NetworkInterface) en.nextElement();
                Enumeration ine = iface.getInetAddresses();
                while (ine.hasMoreElements()) {
                    InetAddress address = (InetAddress) ine.nextElement();
                    if (address.equals(dest)) {
                        isSameMachine = true;
                    }
View Full Code Here

    private static String getIpAddress() throws SocketException {
        Enumeration e = NetworkInterface.getNetworkInterfaces();
        String address = "127.0.0.1";

        while (e.hasMoreElements()) {
            NetworkInterface netface = (NetworkInterface) e.nextElement();
            Enumeration addresses = netface.getInetAddresses();

            while (addresses.hasMoreElements()) {
                InetAddress ip = (InetAddress) addresses.nextElement();
                if (!ip.isLoopbackAddress() && isIP(ip.getHostAddress())) {
                    return ip.getHostAddress();
View Full Code Here

    private static String getIpAddress() throws SocketException {
        Enumeration e = NetworkInterface.getNetworkInterfaces();
        String address = "127.0.0.1";

        while (e.hasMoreElements()) {
            NetworkInterface netface = (NetworkInterface) e.nextElement();
            Enumeration addresses = netface.getInetAddresses();

            while (addresses.hasMoreElements()) {
                InetAddress ip = (InetAddress) addresses.nextElement();
                if (!ip.isLoopbackAddress() && isIP(ip.getHostAddress())) {
                    return ip.getHostAddress();
View Full Code Here

        public List<String> call() throws IOException {
            List<String> names = new ArrayList<String>();

            Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
            while (nis.hasMoreElements()) {
                NetworkInterface ni =  nis.nextElement();
                LOGGER.fine("Listing up IP addresses for "+ni.getDisplayName());
                Enumeration<InetAddress> e = ni.getInetAddresses();
                while (e.hasMoreElements()) {
                    InetAddress ia =  e.nextElement();
                    if(ia.isLoopbackAddress()) {
                        LOGGER.fine(ia+" is a loopback address");
                        continue;
View Full Code Here

        }
        try {
            InetAddress dest = InetAddress.getByName(hostname);
            Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
            while (en.hasMoreElements()) {
                NetworkInterface iface = en.nextElement();
                Enumeration<InetAddress> ine = iface.getInetAddresses();
                while (ine.hasMoreElements()) {
                    InetAddress address = ine.nextElement();
                    if (address.equals(dest)) {
                        isSameMachine = true;
                    }
View Full Code Here

            if (hostAddress.isAnyLocalAddress() || hostAddress.isLoopbackAddress() || hostName.equals(getLocalHostName()) || hostName.equals(getFullLocalHostName())) {
                return true;
            } else {
                Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
                while (en.hasMoreElements()) {
                    NetworkInterface iface = en.nextElement();
                    Enumeration<InetAddress> ien = iface.getInetAddresses();
                    while (ien.hasMoreElements()) {
                        InetAddress address = ien.nextElement();
                        if (address.equals(hostAddress)) {
                            return true;
                        }
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.