List of usage examples for java.net NetworkInterface getByInetAddress
public static NetworkInterface getByInetAddress(InetAddress addr) throws SocketException
From source file:de.nmichael.efa.Daten.java
public static Vector getEfaInfos(boolean efaInfos, boolean pluginInfos, boolean javaInfos, boolean hostInfos, boolean jarInfos) { Vector infos = new Vector(); // efa-Infos/*from w w w. ja v a2 s. c o m*/ if (efaInfos) { infos.add("efa.version=" + Daten.VERSIONID); if (EFALIVE_VERSION != null && EFALIVE_VERSION.length() > 0) { infos.add("efalive.version=" + Daten.EFALIVE_VERSION); } if (applID != APPL_EFABH || applMode == APPL_MODE_ADMIN) { if (Daten.efaMainDirectory != null) { infos.add("efa.dir.main=" + Daten.efaMainDirectory); } if (Daten.efaBaseConfig != null && Daten.efaBaseConfig.efaUserDirectory != null) { infos.add("efa.dir.user=" + Daten.efaBaseConfig.efaUserDirectory); } if (Daten.efaProgramDirectory != null) { infos.add("efa.dir.program=" + Daten.efaProgramDirectory); } if (Daten.efaPluginDirectory != null) { infos.add("efa.dir.plugin=" + Daten.efaPluginDirectory); } if (Daten.efaDocDirectory != null) { infos.add("efa.dir.doc=" + Daten.efaDocDirectory); } if (Daten.efaDataDirectory != null) { infos.add("efa.dir.data=" + Daten.efaDataDirectory); } if (Daten.efaCfgDirectory != null) { infos.add("efa.dir.cfg=" + Daten.efaCfgDirectory); } if (Daten.efaBakDirectory != null) { infos.add("efa.dir.bak=" + Daten.efaBakDirectory); } if (Daten.efaTmpDirectory != null) { infos.add("efa.dir.tmp=" + Daten.efaTmpDirectory); } } } // efa Plugin-Infos if (pluginInfos) { try { File dir = new File(Daten.efaPluginDirectory); if ((applID != APPL_EFABH || applMode == APPL_MODE_ADMIN) && Logger.isDebugLogging()) { File[] files = dir.listFiles(); for (File file : files) { if (file.isFile()) { infos.add("efa.plugin.file=" + file.getName() + ":" + file.length()); } } } Plugins plugins = Plugins.getPluginInfoFromLocalFile(); String[] names = plugins.getAllPluginNames(); for (String name : names) { infos.add("efa.plugin." + name + "=" + (Plugins.isPluginInstalled(name) ? "installed" : "not installed")); } } catch (Exception e) { Logger.log(Logger.ERROR, Logger.MSG_CORE_INFOFAILED, International.getString("Programminformationen konnten nicht ermittelt werden") + ": " + e.toString()); return null; } } // Java Infos if (javaInfos) { infos.add("java.version=" + System.getProperty("java.version")); infos.add("java.vendor=" + System.getProperty("java.vendor")); infos.add("java.home=" + System.getProperty("java.home")); infos.add("java.vm.version=" + System.getProperty("java.vm.version")); infos.add("java.vm.vendor=" + System.getProperty("java.vm.vendor")); infos.add("java.vm.name=" + System.getProperty("java.vm.name")); infos.add("os.name=" + System.getProperty("os.name")); infos.add("os.arch=" + System.getProperty("os.arch")); infos.add("os.version=" + System.getProperty("os.version")); if (applID != APPL_EFABH || applMode == APPL_MODE_ADMIN) { infos.add("user.home=" + System.getProperty("user.home")); infos.add("user.name=" + System.getProperty("user.name")); infos.add("user.dir=" + System.getProperty("user.dir")); infos.add("java.class.path=" + System.getProperty("java.class.path")); } } // Host Infos if (hostInfos) { if (applID != APPL_EFABH || applMode == APPL_MODE_ADMIN) { try { infos.add("host.name=" + InetAddress.getLocalHost().getCanonicalHostName()); infos.add("host.ip=" + InetAddress.getLocalHost().getHostAddress()); infos.add("host.interface=" + EfaUtil .getInterfaceInfo(NetworkInterface.getByInetAddress(InetAddress.getLocalHost()))); } catch (Exception eingore) { } } } // JAR methods if (jarInfos && Logger.isDebugLogging()) { try { String cp = System.getProperty("java.class.path"); while (cp != null && cp.length() > 0) { int pos = cp.indexOf(";"); if (pos < 0) { pos = cp.indexOf(":"); } String jarfile; if (pos >= 0) { jarfile = cp.substring(0, pos); cp = cp.substring(pos + 1); } else { jarfile = cp; cp = null; } if (jarfile != null && jarfile.length() > 0 && new File(jarfile).isFile()) { try { infos.add("java.jar.filename=" + jarfile); JarFile jar = new JarFile(jarfile); Enumeration _enum = jar.entries(); Object o; while (_enum.hasMoreElements() && (o = _enum.nextElement()) != null) { infos.add( "java.jar.content=" + o + ":" + (jar.getEntry(o.toString()) == null ? "null" : Long.toString(jar.getEntry(o.toString()).getSize()))); } jar.close(); } catch (Exception e) { Logger.log(Logger.ERROR, Logger.MSG_CORE_INFOFAILED, e.toString()); return null; } } } } catch (Exception e) { Logger.log(Logger.ERROR, Logger.MSG_CORE_INFOFAILED, International.getString("Programminformationen konnten nicht ermittelt werden") + ": " + e.toString()); return null; } } return infos; }
From source file:com.emc.storageos.systemservices.impl.upgrade.CoordinatorClientExt.java
/** * check whether current node is virtual IP holder *//*from w ww . j a v a 2 s. c o m*/ public boolean isVirtualIPHolder() { try { //standby node with vip will monitor all node states InetAddress vip = InetAddress.getByName(getVip()); return (NetworkInterface.getByInetAddress(vip) != null); } catch (Exception e) { _log.error("Error occured while determining leading node for monitor", e); return false; } }
From source file:org.quickserver.net.server.QuickServer.java
/** * Returns a ServerSocket object to be used for listening. * @since 1.4.0//from ww w . ja v a2 s . co m */ protected void makeServerSocket() throws BindException, IOException { server = null; logger.log(Level.FINEST, "Binding {0} to IP: {1}", new Object[] { getName(), getBindAddr() }); InetSocketAddress bindAddress = new InetSocketAddress(getBindAddr(), getPort()); try { NetworkInterface ni = NetworkInterface.getByInetAddress(getBindAddr()); if (ni != null) { logger.fine("NetworkInterface: " + ni); } } catch (Exception igrnore) { /*ignore*/} catch (Error igrnore) { /*ignore*/} if (getSecure().isEnable() == false) { logger.log(Level.FINE, "Making a normal ServerSocket for {0}", getName()); setRunningSecure(false); if (getBlockingMode() == false) { //for non-blocking serverSocketChannel = ServerSocketChannel.open(); server = serverSocketChannel.socket(); server.bind(bindAddress, getBasicConfig().getAdvancedSettings().getBacklog()); } else { //for blocking server = new ServerSocket(getPort(), getBasicConfig().getAdvancedSettings().getBacklog(), getBindAddr()); } } else { try { logger.log(Level.FINE, "Making a secure ServerSocket for {0}", getName()); getSSLContext(); setRunningSecure(true); if (getBlockingMode() == false) { logger.log(Level.FINE, "Making a secure ServerSocketChannel for {0}", getName()); //for non-blocking serverSocketChannel = ServerSocketChannel.open(); server = serverSocketChannel.socket(); server.bind(bindAddress, getBasicConfig().getAdvancedSettings().getBacklog()); } else { ServerSocketFactory ssf = getSSLContext().getServerSocketFactory(); SSLServerSocket serversocket = (SSLServerSocket) ssf.createServerSocket(getPort(), getBasicConfig().getAdvancedSettings().getBacklog(), getBindAddr()); serversocket.setNeedClientAuth(secure.isClientAuthEnable()); setRunningSecure(true); secureStoreManager.logSSLServerSocketInfo(serversocket); server = serversocket; serverSocketChannel = server.getChannel(); if (serverSocketChannel == null && getBlockingMode() == false) { logger.warning("Secure Server does not support Channel! So will run in blocking mode."); blockingMode = false; } } //blocking } catch (NoSuchAlgorithmException e) { logger.log(Level.WARNING, "NoSuchAlgorithmException : {0}", e); throw new IOException("Error creating secure socket : " + e.getMessage()); } catch (KeyManagementException e) { logger.log(Level.WARNING, "KeyManagementException : {0}", e); throw new IOException("Error creating secure socket : " + e.getMessage()); } } server.setReuseAddress(true); int connectionTime = 0; int latency = 0; int bandwidth = 0; connectionTime = getBasicConfig().getAdvancedSettings().getPerformancePreferencesConnectionTime(); latency = getBasicConfig().getAdvancedSettings().getPerformancePreferencesLatency(); bandwidth = getBasicConfig().getAdvancedSettings().getPerformancePreferencesBandwidth(); logger.log(Level.FINE, "getPerformancePreferencesConnectionTime : {0}", connectionTime); logger.log(Level.FINE, "getPerformancePreferencesLatency : {0}", latency); logger.log(Level.FINE, "getPerformancePreferencesBandwidth : {0}", bandwidth); server.setPerformancePreferences(connectionTime, latency, bandwidth); int clientSocketReceiveBufferSize = getBasicConfig().getAdvancedSettings() .getClientSocketReceiveBufferSize(); if (clientSocketReceiveBufferSize > 0) { logger.log(Level.FINE, "clientSocketReceiveBufferSize: {0}", clientSocketReceiveBufferSize); server.setReceiveBufferSize(clientSocketReceiveBufferSize); } if (getBlockingMode() == false) { logger.log(Level.FINE, "Server Mode {0} - Non Blocking", getName()); if (selector == null || selector.isOpen() == false) { logger.finest("Opening new selector"); selector = Selector.open(); } else { logger.log(Level.FINEST, "Reusing selector: {0}", selector); } serverSocketChannel.configureBlocking(false); serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT); selector.wakeup(); } else { logger.log(Level.FINE, "Server Mode {0} - Blocking", getName()); } }
From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java
private void initSettingsConfig() { Settings s = Settings.getInstance(); settingsFolderTextField.setText(s.getConfDir()); panboxFolderTextField.setText(s.getMountDir()); languageComboBox.setSelectedItem(SupportedLanguage.fromShorthand(s.getLanguage())); expertModeCheckBox.setSelected(s.getExpertMode()); uriHandlerCheckbox.setSelected(s.isUriHandlerSupported()); if (uriHandlerCheckbox.isSelected()) { clipboardHandlerCheckbox.setEnabled(true); clipboardHandlerCheckbox.setSelected(s.isClipboardHandlerSupported()); } else {//from ww w.j a va 2 s. com clipboardHandlerCheckbox.setEnabled(false); clipboardHandlerCheckbox.setSelected(false); } mailtoSchemeCheckbox.setSelected(s.isMailtoSchemeSupported()); if (cspSelectionComboBox.getModel().getSize() > 0) { // in case dropbox has been found select it by default selectedCSPContentPanel.removeAll(); selectedCSPContentPanel.add(dropboxSettingsPanel); } NetworkInterface nic; try { if (s.getPairingAddress() == null) { // no network interface found! DefaultComboBoxModel<Object> noNicModel = new DefaultComboBoxModel<>(); noNicModel.addElement(bundle.getString("client.networkinterface.notexisting")); networkInterfaceComboBox.setModel(noNicModel); networkAddressComboBox.setModel(noNicModel); return; // finish from here } DefaultComboBoxModel<Object> model = generateNetworkInterfacesModel(); nic = NetworkInterface.getByInetAddress(s.getPairingAddress()); if (nic == null) { // The configured IP address does not exist anymore! Will reset // to localhost s.setPairingAddress(InetAddress.getByName("localhost")); nic = NetworkInterface.getByInetAddress(s.getPairingAddress()); } model.setSelectedItem(nic); networkInterfaceComboBox.setModel(model); networkAddressComboBox.setModel(generateNetworkAddressModel(nic)); } catch (SocketException | UnknownHostException e) { logger.warn("Paiting settings Exception", e); } }