package mil.navy.nps.dis; import java.net.*; import org.web3d.vrtp.security.*; // Security stuff (dangerous, not very secure) /** * A utility class that is used to determine the status * of the network. As of this writing, it only is used * to determine if we have an interface other than the * loopback interface up. This implements the SecuirtyBadge * scheme, so that we can use it in x-platform browsers * with different security schemes. * * @author DMcG * @ @version 1.0 */ public class NetworkStatus extends Object implements NetworkCommBadge { boolean isConnected = false; /** * Used to test for the existence of network connections. Returns true * if there is at least one interface that is not "127.0.0.1". Since * microsoft refuses to make the loopback interface multicast- * enabled, this is effectively a test to see whether we have * an interface that can use mcast. */ public boolean networkConnectionPresent() { InetAddress local; // Our IP InetAddress interfaces[]; // All IPs on the system (see below for special rules on loopback) boolean connected = false; // At least one of the IPs is not 127.0.0.1, the loopback // The reality, under windows: // - With no network card, we get one interface, 127.0.0.1, the loopback. // - with one network card, we get one interface, 131.120.7.4 or whatever // - with multiple real or virtual interfaces, we get multiple IPs // - we do NOT get the loopback interface listed if we have a non-loopback interface System.out.println("Starting networkConnectionPresent"); try { local = InetAddress.getLocalHost(); interfaces = InetAddress.getAllByName(local.getHostName()); for(int idx=0; idx < interfaces.length; idx++) { if(interfaces[idx].getHostAddress().indexOf("127.0.0.1") == -1) // not found { connected = true; System.out.println("interface found: " + interfaces[idx]); } } } catch(Exception e) { System.out.println("Exception networkConnectionPresent"); System.out.println(e); } isConnected = connected; return connected; } }