List of usage examples for java.net InetAddress getHostName
public String getHostName()
From source file:DNSLookup.java
public static void main(String args[]) { try {/* w w w . java2 s . co m*/ InetAddress host; if (args.length == 0) { host = InetAddress.getLocalHost(); } else { host = InetAddress.getByName(args[0]); } System.out.println("Host:'" + host.getHostName() + "' has address: " + host.getHostAddress()); byte bytes[] = host.getAddress(); int fourBytes[] = new int[bytes.length]; for (int i = 0, n = bytes.length; i < n; i++) { fourBytes[i] = bytes[i] & 255; } System.out.println("\t" + fourBytes[0] + "." + fourBytes[1] + "." + fourBytes[2] + "." + fourBytes[3]); } catch (UnknownHostException e) { e.printStackTrace(); } }
From source file:org.apache.common.net.examples.ntp.NTPClient.java
public static final void main(String[] args) { if (args.length == 0) { System.err.println("Usage: NTPClient <hostname-or-address-list>"); System.exit(1);//from w w w . j av a 2 s.c om } NTPUDPClient client = new NTPUDPClient(); // We want to timeout if a response takes longer than 10 seconds client.setDefaultTimeout(10000); try { client.open(); for (int i = 0; i < args.length; i++) { System.out.println(); try { InetAddress hostAddr = InetAddress.getByName(args[i]); System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress()); TimeInfo info = client.getTime(hostAddr); processResponse(info); } catch (IOException ioe) { ioe.printStackTrace(); } } } catch (SocketException e) { e.printStackTrace(); } client.close(); }
From source file:NTP_Example.java
public static void main(String[] args) { if (args.length == 0) { System.err.println("Usage: NTPClient <hostname-or-address-list>"); System.exit(1);//from ww w . j av a 2 s. c om } NTPUDPClient client = new NTPUDPClient(); // We want to timeout if a response takes longer than 10 seconds client.setDefaultTimeout(10000); try { client.open(); for (String arg : args) { System.out.println(); try { InetAddress hostAddr = InetAddress.getByName(arg); System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress()); TimeInfo info = client.getTime(hostAddr); processResponse(info); } catch (IOException ioe) { ioe.printStackTrace(); } } } catch (SocketException e) { e.printStackTrace(); } client.close(); }
From source file:org.urbancortex.routes.NTPClient.java
public static TimeInfo main(String[] args) { System.out.println(args);/*from w w w . ja v a 2 s . com*/ if (args.length == 0) { System.err.println("Usage: NTPClient <hostname-or-address-list>"); System.exit(1); } NTPUDPClient client = new NTPUDPClient(); // We want to timeout if a response takes longer than 10 seconds client.setDefaultTimeout(10000); try { client.open(); for (String arg : args) { System.out.println(); try { InetAddress hostAddr = InetAddress.getByName(arg); System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress()); TimeInfo info = client.getTime(hostAddr); processResponse(info); return info; } catch (IOException ioe) { ioe.printStackTrace(); } } } catch (SocketException e) { e.printStackTrace(); } client.close(); return null; }
From source file:ntp.NTPClient.java
public static void main(String[] args) { Properties defaultProps = System.getProperties(); //obtiene las "properties" del sistema defaultProps.put("java.net.preferIPv6Addresses", "true");//mapea el valor true en la variable java.net.preferIPv6Addresses if (args.length == 0) { System.err.println("Usage: NTPClient <hostname-or-address-list>"); System.exit(1);/*from w w w . j a v a 2 s. co m*/ } Promedio = 0; Cant = 0; NTPUDPClient client = new NTPUDPClient(); // We want to timeout if a response takes longer than 10 seconds client.setDefaultTimeout(10000); try { client.open(); for (String arg : args) { System.out.println(); try { InetAddress hostAddr = InetAddress.getByName(arg); System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress()); TimeInfo info = client.getTime(hostAddr); processResponse(info); } catch (IOException ioe) { System.err.println(ioe.toString()); } } } catch (SocketException e) { System.err.println(e.toString()); } client.close(); System.out.println("\n Pomedio " + (Promedio / Cant)); }
From source file:org.urbancortex.presenter.NTPClient.java
public static TimeInfo main(String[] args) { System.out.println(args);/*w ww .j a v a 2s .c om*/ if (args.length == 0) { System.err.println("Usage: NTPClient <hostname-or-address-list>"); System.exit(1); } NTPUDPClient client = new NTPUDPClient(); // We want to timeout if a response takes longer than 10 seconds client.setDefaultTimeout(5000); try { client.open(); for (String arg : args) { System.out.println(); try { InetAddress hostAddr = InetAddress.getByName(arg); System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress()); TimeInfo info = client.getTime(hostAddr); processResponse(info); return info; } catch (IOException ioe) { ioe.printStackTrace(); socketTimeout = true; // csv_logger.stopNTPTask(); System.out.println("couldn't establish a connection" + ioe); } } } catch (SocketException e) { e.printStackTrace(); socketTimeout = true; // csv_logger.stopNTPTask(); System.out.println("couldn't establish a connection" + e); } client.close(); return null; }
From source file:org.wso2.carbon.server.Main.java
/** * Launch the Carbon server.// ww w. jav a 2s. c om * 1) Process and set system properties * 2) Invoke extensions. * 3) Launch OSGi framework. * * @param args command line arguments. */ public static void main(String[] args) { //Setting Carbon Home if (System.getProperty(LauncherConstants.CARBON_HOME) == null) { System.setProperty(LauncherConstants.CARBON_HOME, "."); } System.setProperty(LauncherConstants.AXIS2_HOME, System.getProperty(LauncherConstants.CARBON_HOME)); //To keep track of the time taken to start the Carbon server. System.setProperty("wso2carbon.start.time", System.currentTimeMillis() + ""); if (System.getProperty("carbon.instance.name") == null) { InetAddress addr; String ipAddr; String hostName; try { addr = InetAddress.getLocalHost(); ipAddr = addr.getHostAddress(); hostName = addr.getHostName(); } catch (UnknownHostException e) { ipAddr = "localhost"; hostName = "127.0.0.1"; } String uuId = UUID.randomUUID().toString(); String timeStamp = System.currentTimeMillis() + ""; String carbon_instance_name = timeStamp + "_" + hostName + "_" + ipAddr + "_" + uuId; System.setProperty("carbon.instance.name", carbon_instance_name); } writePID(System.getProperty(LauncherConstants.CARBON_HOME)); processCmdLineArgs(args); // set WSO2CarbonProfile as worker if workerNode=true present if ((System.getProperty(LauncherConstants.WORKER_NODE) != null) && (System.getProperty(LauncherConstants.WORKER_NODE).equals("true")) && System.getProperty(LauncherConstants.PROFILE) == null) { File profileDir = new File( Utils.getCarbonComponentRepo() + File.separator + LauncherConstants.WORKER_PROFILE); /* * Better check profile directory is present or not otherwise osgi will hang * */ if (!profileDir.exists()) { log.fatal("OSGi runtime " + LauncherConstants.WORKER_PROFILE + " profile not found"); throw new RuntimeException(LauncherConstants.WORKER_PROFILE + " profile not found"); } System.setProperty(LauncherConstants.PROFILE, LauncherConstants.WORKER_PROFILE); } //setting default WSO2CarbonProfile as the running Profile if no other Profile is given as an argument if (System.getProperty(LauncherConstants.PROFILE) == null) { System.setProperty(LauncherConstants.PROFILE, LauncherConstants.DEFAULT_CARBON_PROFILE); } invokeExtensions(); removeAllAppendersFromCarbon(); launchCarbon(); }
From source file:org.wso2.carbon.micro.integrator.server.Main.java
public static void main(String[] args) { //Setting Carbon Home if (System.getProperty(LauncherConstants.CARBON_HOME) == null) { System.setProperty(LauncherConstants.CARBON_HOME, "."); }/*www.j av a2s . c om*/ System.setProperty(LauncherConstants.AXIS2_HOME, System.getProperty(LauncherConstants.CARBON_HOME)); //To keep track of the time taken to start the Carbon server. System.setProperty("wso2carbon.start.time", System.currentTimeMillis() + ""); if (System.getProperty("carbon.instance.name") == null) { InetAddress addr; String ipAddr; String hostName; try { addr = InetAddress.getLocalHost(); ipAddr = addr.getHostAddress(); hostName = addr.getHostName(); } catch (UnknownHostException e) { ipAddr = "localhost"; hostName = "127.0.0.1"; } String uuId = UUID.randomUUID().toString(); String timeStamp = System.currentTimeMillis() + ""; String carbon_instance_name = timeStamp + "_" + hostName + "_" + ipAddr + "_" + uuId; System.setProperty("carbon.instance.name", carbon_instance_name); } writePID(System.getProperty(LauncherConstants.CARBON_HOME)); processCmdLineArgs(args); invokeExtensions(); removeAllAppendersFromCarbon(); startEquinox(); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSwingHttpCLI.CFAsteriskSwingHttpCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSwingHttpCLI.main() "; initConsoleLog();/*from w ww. j a v a 2 s . c om*/ boolean fastExit = false; String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskClientConfigurationFile cFAsteriskClientConfig = new CFAsteriskClientConfigurationFile(); String cFAsteriskClientConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskclientrc"; cFAsteriskClientConfig.setFileName(cFAsteriskClientConfigFileName); File cFAsteriskClientConfigFile = new File(cFAsteriskClientConfigFileName); if (!cFAsteriskClientConfigFile.exists()) { String cFAsteriskKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFAsteriskClientConfig.setKeyStore(cFAsteriskKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFAsteriskClientConfig.setDeviceName(deviceName); cFAsteriskClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFAsteriskClientConfigFileName); fastExit = true; } if (!cFAsteriskClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFAsteriskClientConfigFileName + " is not a file."); fastExit = true; } if (!cFAsteriskClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFAsteriskClientConfigFileName); fastExit = true; } cFAsteriskClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); // The Invoker and it's implementation CFAsteriskXMsgClientHttpSchema invoker = new CFAsteriskXMsgClientHttpSchema(); // And now for the client side cache implementation that invokes it ICFAsteriskSchemaObj clientSchemaObj = new CFAsteriskSchemaObj() { public void logout() { CFAsteriskXMsgClientHttpSchema invoker = (CFAsteriskXMsgClientHttpSchema) getBackingStore(); try { invoker.logout(getAuthorization()); } catch (RuntimeException e) { } setAuthorization(null); } }; clientSchemaObj.setBackingStore(invoker); // And stitch the response handler to reference our client instance invoker.setResponseHandlerSchemaObj(clientSchemaObj); // And now we can stitch together the CLI to the SAX loader code CFAsteriskSwingHttpCLI cli = new CFAsteriskSwingHttpCLI(); cli.setXMsgClientHttpSchema(invoker); cli.setSchema(clientSchemaObj); ICFAsteriskSwingSchema swing = cli.getSwingSchema(); swing.setClientConfigurationFile(cFAsteriskClientConfig); swing.setSchema(clientSchemaObj); swing.setClusterName("system"); swing.setTenantName("system"); swing.setSecUserName("system"); JFrame jframe = cli.getDesktop(); jframe.setVisible(true); jframe.toFront(); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxDb2LUWLoaderCLI.CFAsteriskSaxDb2LUWLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxDb2LUWLoaderCLI.main() "; initConsoleLog();// w ww .j a va 2 s . c om int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskdb2luwrc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("127.0.0.1"); cFAsteriskConfig.setDbPort(5432); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("luw"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskDb2LUWSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxDb2LUWLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }