List of usage examples for java.net UnknownHostException printStackTrace
public void printStackTrace()
From source file:Main.java
public static String getBroadcastAddress(Context context) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); DhcpInfo dhcp = wifi.getDhcpInfo();/*ww w . ja v a2s . co m*/ int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask; byte[] quads = new byte[4]; for (int k = 0; k < 4; k++) quads[k] = (byte) (broadcast >> (k * 8)); try { return InetAddress.getByAddress(quads).getHostAddress(); } catch (UnknownHostException e) { e.printStackTrace(); } return "255.255.255.255"; }
From source file:Main.java
/** * parse InetAddress/*from www . ja v a 2s .c o m*/ * * @param inetAddrBytes * @return */ public static InetAddress parseInetAddr(byte[] inetAddrBytes, int offset, int count) { InetAddress inetAddress = null; StringBuilder sb = new StringBuilder(); for (int i = 0; i < count; i++) { sb.append(Integer.toString(inetAddrBytes[offset + i] & 0xff)); if (i != count - 1) { sb.append('.'); } } try { inetAddress = InetAddress.getByName(sb.toString()); } catch (UnknownHostException e) { e.printStackTrace(); } return inetAddress; }
From source file:Main.java
/** * get the local ip address by Android System * //from ww w .ja v a 2 s . c om * @param context * the context * @return the local ip addr allocated by Ap */ public static InetAddress getLocalInetAddress(Context context) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wm.getConnectionInfo(); int localAddrInt = wifiInfo.getIpAddress(); String localAddrStr = __formatString(localAddrInt); InetAddress localInetAddr = null; try { localInetAddr = InetAddress.getByName(localAddrStr); } catch (UnknownHostException e) { e.printStackTrace(); } return localInetAddr; }
From source file:Main.java
/** * Calculates the network mask address from the value * //from ww w . java2 s .c o m * @param numericMask * the network mask * @return */ public static String networkMaskFromInt(int numericMask) { // StringBuffer sb = new StringBuffer(15); // for (int shift = 24; shift > 0; shift -= 8) { // // process 3 bytes, from high order byte down. // sb.append(Integer.toString((numericMask >>> shift) & 0xff)); // sb.append('.'); // } // sb.append(Integer.toString(numericMask & 0xff)); // return sb.toString(); // } // // public String getMaskAsString() { int value = 0xffffffff << (32 - numericMask); byte[] bytes = new byte[] { (byte) (value >>> 24), (byte) (value >> 16 & 0xff), (byte) (value >> 8 & 0xff), (byte) (value & 0xff) }; InetAddress netAddr = null; try { netAddr = InetAddress.getByAddress(bytes); } catch (UnknownHostException e) { e.printStackTrace(); } return netAddr.getHostAddress(); }
From source file:Main.java
public static String getDomainAddress(final String domain) { try {/*from w w w . ja v a 2 s.co m*/ ExecutorService exec = Executors.newCachedThreadPool(); Future<String> fs = exec.submit(new Callable<String>() { @Override public String call() throws Exception { InetAddress inetAddress; try { inetAddress = InetAddress.getByName(domain); return inetAddress.getHostAddress(); } catch (UnknownHostException e) { e.printStackTrace(); } return null; } }); return fs.get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } return null; }
From source file:org.apache.eagle.topology.utils.EntityBuilderHelper.java
public static String resolveHostByIp(String ip) { InetAddress addr = null;/* w w w . j a v a 2 s.com*/ try { addr = InetAddress.getByName(ip); } catch (UnknownHostException e) { e.printStackTrace(); } return addr.getHostName(); }
From source file:org.csstudio.domain.common.net.GatewayUtil.java
public static boolean hasGateway() { boolean inSubnet = false; try {//from w w w. j av a2s . co m final InetAddress localHost = InetAddress.getLocalHost(); final String myAddress = localHost.getHostAddress(); final List<SubnetUtils> controlSubnets = getControlSubnets(); for (final SubnetUtils subnetUtils : controlSubnets) { inSubnet |= subnetUtils.getInfo().isInRange(myAddress); } } catch (final UnknownHostException e) { e.printStackTrace(); } finally { } return !inSubnet; }
From source file:Main.java
public static InetAddress ipIntToInet4Address(int ip) { byte[] ipAddress = new byte[4]; writeInt(ipAddress, 0, ip);//from w ww. ja v a 2 s .com try { return Inet4Address.getByAddress(ipAddress); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:Main.java
public static String getHostName(String ip) { String hostName = "Unknown"; try {/*from w w w . java2 s . co m*/ InetAddress add = InetAddress.getByName(ip); hostName = add.getHostName(); Log.d(Tag, "host name is " + hostName); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } return hostName; }
From source file:Main.java
/** * Performs execution of the shell command on remote host. * @param host ip address or name of the host. * @param port telnet port/*from w w w . j a va 2 s . c o m*/ * @param command shell command to be executed. * @return true if success, false on error. */ public static final boolean executeRemotely(String host, int port, String command) { Socket socket = null; OutputStream os = null; try { socket = new Socket(host, port); os = socket.getOutputStream(); os.write(command.getBytes()); os.flush(); return true; } catch (UnknownHostException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } finally { if (os != null) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } if (socket != null && !socket.isClosed()) { try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } } }