List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:com.beetle.framework.util.OtherUtil.java
/** * ???//from w w w.j a va 2s. com * * @return */ public static String getLocalHostName() { if (localHostname.equals("")) { try { localHostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { localHostname = "UnknownHost"; } } return localHostname; }
From source file:com.yamanyar.esb.services.XmlEcho.java
public Source issueResponseFor(DOMSource request) { String address;//from ww w.ja v a 2 s.com try { address = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { //use default address address = "test-server"; logger.error("Can not find local host name", e); } return new DomSourceFactory().createSource("<echoResponse xmlns=\"http://" + address + "/echo\">" + request.getNode().getTextContent() + "</echoResponse>"); }
From source file:com.ms.commons.utilities.CoreUtilities.java
/** * IP??getHostAddress()??Linux?//www.j av a2 s. co m */ public static String getIPAddress() { if (ipAddress != null && ipAddress.length() > 0) { return ipAddress; } String hostIp = null; try { hostIp = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { logger.error("UnknownHostException", e); } catch (Exception e) { logger.error("Exception", e); } if (hostIp != null) { String tmpIp = hostIp.toLowerCase(); if (tmpIp.startsWith("localhost")) { hostIp = null; } else if (tmpIp.startsWith("127")) { hostIp = null; } } if (hostIp != null) { ipAddress = hostIp; return ipAddress; } try { ipAddress = getIfconig(); } catch (Exception e) { logger.error("getIfconig Error", e); ipAddress = "unknownIp"; } return ipAddress; }
From source file:Dengue.CDengueManager.java
private static void sendInfoToCPU(String pStrJSON, int pIntPort) { new Thread(() -> { try (Socket client = new Socket(InetAddress.getLocalHost(), pIntPort)) { Writer objWriter = Channels.newWriter(Channels.newChannel(client.getOutputStream()), StandardCharsets.US_ASCII.name()); objWriter.write(pStrJSON);/*from w w w. ja va2 s . c o m*/ objWriter.flush(); client.shutdownOutput(); try (Reader objReader = Channels.newReader(Channels.newChannel(client.getInputStream()), StandardCharsets.US_ASCII.name()); BufferedReader objOutReader = new BufferedReader(objReader)) { System.out.println((char) objOutReader.read()); } } catch (IOException e) { System.out.println(e); } }).start(); }
From source file:br.ufac.sion.audit.CustomRevisionEntityListener.java
@Override public void newRevision(Object revisionEntity) { try {//from ww w .ja va2 s . c o m CustomRevisionEntity customRevisionEntity = (CustomRevisionEntity) revisionEntity; Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); System.out.println("authentication == null : " + (authentication == null)); if (authentication == null) { customRevisionEntity.setUsername("Sion - tarefa automatizada!"); } else { customRevisionEntity.setUsername(authentication.getName()); } customRevisionEntity.setIp(InetAddress.getLocalHost().getHostAddress()); } catch (Exception ex) { log.error("Erro de sistema (sion-web): " + ex.getMessage(), ex); } }
From source file:de.pawlidi.openaletheia.utils.AletheiaUtils.java
/** * Read java networt mac adress/*from w w w. j ava 2 s . c om*/ * * @return */ public static String getJavaNetMacAddress() { String javaMacAdress = null; try { InetAddress ip = InetAddress.getLocalHost(); if (ip == null) { return null; } NetworkInterface network = NetworkInterface.getByInetAddress(ip); if (network == null) { return null; } byte[] mac = network.getHardwareAddress(); javaMacAdress = Converter.hexToString(mac); } catch (UnknownHostException e) { // ignore exception } catch (SocketException e) { // ignore exception } return javaMacAdress; }
From source file:net.dfs.user.test.Store.java
/** * Store application will be started with the main() of the {@link Store}. * //from ww w . j a va 2s . c om * @param args the parameter which is passed to the main() * @throws IOException */ public static void userStarter() throws IOException { Store.context = new ClassPathXmlApplicationContext("net\\dfs\\user\\test\\spring-user.xml"); log.debug("The User " + InetAddress.getLocalHost().getHostAddress() + " Started"); }
From source file:net.sourceforge.jabm.spring.PRNGSeedFactoryBean.java
@Override public Integer getObject() { try {/*www . j a v a2 s. co m*/ int time = new java.util.Date().hashCode(); int ipAddress = InetAddress.getLocalHost().hashCode(); int rand = metaPrng.nextInt(); int seed = (ipAddress & 0xffff) | ((time & 0x00ff) << 32) | (rand & 0x0f000000); logger.info("seed = " + seed); return seed; } catch (UnknownHostException e) { throw new RuntimeException(e); } }
From source file:org.pentaho.reporting.designer.core.auth.AuthenticationHelper.java
public static Credentials getCredentials(final String user, final String password) { if (StringUtils.isEmpty(user)) { return null; }// w w w. ja va 2 s. co m final Configuration config = ReportDesignerBoot.getInstance().getGlobalConfig(); if ("true".equals(config.getConfigProperty(NT_AUTH_CONFIGKEY, "false")) == false) { return new UsernamePasswordCredentials(user, password); } final int domainIdx = user.indexOf(DOMAIN_SEPARATOR); if (domainIdx == -1) { return new UsernamePasswordCredentials(user, password); } try { final String domain = user.substring(0, domainIdx); final String username = user.substring(domainIdx + 1); final String host = InetAddress.getLocalHost().getHostName(); return new NTCredentials(username, password, host, domain); } catch (UnknownHostException uhe) { return new UsernamePasswordCredentials(user, password); } }
From source file:com.anyi.gp.license.RegisterTools.java
public static String getHostName() { try {//from www.ja va2 s . c o m return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { e.printStackTrace(); } return ""; }