List of usage examples for java.net SocketException toString
public String toString()
From source file:Main.java
public static String getIfIpAddress() { String result = ""; try {/*from w w w. ja v a 2 s .c om*/ for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); // Log.v("","ip="+inetAddress.getHostAddress()); if (!inetAddress.isLoopbackAddress() && (inetAddress.getHostAddress().startsWith("0") || inetAddress.getHostAddress().startsWith("1") || inetAddress.getHostAddress().startsWith("2"))) { result = inetAddress.getHostAddress(); break; } } } } catch (SocketException ex) { Log.e(DEBUG_TAG, ex.toString()); result = "192.168.0.1"; } // Log.v("","getIfIpAddress result="+result); if (result.equals("")) result = "192.168.0.1"; return result; }
From source file:Main.java
public static String getIpAddress() { String ipaddress = ""; try {/*from w w w.ja va 2 s . c o m*/ for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { ipaddress = ipaddress + ";" + inetAddress.getHostAddress().toString(); } } } } catch (SocketException ex) { ipaddress = null; Log.e("WifiPreference IpAddress", ex.toString()); } return ipaddress; }
From source file:Main.java
public static String getLocalIpAddress() { String result = ""; boolean exit = false; try {// w w w. j ava 2 s . c om for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); // if (!inetAddress.isLoopbackAddress() && !(inetAddress.toString().indexOf(":")>=0)) { // return inetAddress.getHostAddress().toString(); // } // Log.v("","ip="+inetAddress.getHostAddress()+ // ", name="+intf.getName()); if (inetAddress.isSiteLocalAddress()) { result = inetAddress.getHostAddress(); // Log.v("","result="+result+", name="+intf.getName()+"-"); if (intf.getName().equals("wlan0")) { exit = true; break; } } } if (exit) break; } } catch (SocketException ex) { Log.e(DEBUG_TAG, ex.toString()); result = "192.168.0.1"; } // Log.v("","getLocalIpAddress result="+result); if (result.equals("")) result = "192.168.0.1"; return result; }
From source file:Main.java
/** * Get all device ip addresses// ww w .jav a 2s . c om * @return {@link array} */ public static String[] getLocalIpAddress() { ArrayList<String> addresses = new ArrayList<String>(); try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { //IPAddresses.setText(inetAddress.getHostAddress().toString()); boolean isIPv4 = isIPv4Address(inetAddress.getHostAddress().toString()); if (isIPv4) { addresses.add(inetAddress.getHostAddress().toString()); } } } } } catch (SocketException ex) { String LOG_TAG = null; Log.e(LOG_TAG, ex.toString()); } return addresses.toArray(new String[0]); }
From source file:com.seadee.library.receiver.NetworkStateReceiver.java
public static String getLocalIpAddress(Context context) { final String IPTAG = "getLocalIpAddress"; String nullAddress = "0.0.0.0"; try {// w w w.ja va 2s . c om for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); String ip_address = inetAddress.getHostAddress(); if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(ip_address)) return ip_address; } } } catch (SocketException ex) { Log.e(IPTAG, ex.toString()); } return nullAddress; }
From source file:edu.stanford.junction.provider.jx.JunctionProvider.java
public static String getLocalIpAddress() { try {//from ww w.java 2 s. c o m for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { // not ready for IPv6, apparently. if (!inetAddress.getHostAddress().contains(":")) { return inetAddress.getHostAddress().toString(); } } } } } catch (SocketException ex) { Log.e("junction", ex.toString()); } return null; }
From source file:com.seadee.degree.service.NetworkStateReceiver.java
public static String getLocalIpAddress(Context context) { final String IPTAG = "getLocalIpAddress"; String nullAddress = "0.0.0.0"; try {//w ww . ja v a 2 s .c o m if (SettingVarible.networkstate != SettingVarible.NETWORKSTATE.NONETWORK) { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr .hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); String ip_address = inetAddress.getHostAddress(); if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(ip_address)) return ip_address; } } } } catch (SocketException ex) { Log.e(IPTAG, ex.toString()); } return nullAddress; }
From source file:ntpgraphic.PieChart.java
public static void NTPClient(String[] servers) { 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 (servers.length == 0) { System.err.println("Usage: NTPClient <hostname-or-address-list>"); System.exit(1);/*from w w w . j a v a 2 s .c o m*/ } Promedio = 0; Cant = 0; int j = 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 : servers) { System.out.println(); try { InetAddress hostAddr = InetAddress.getByName(arg); System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress()); TimeInfo info = client.getTime(hostAddr); processResponse(info, j++); } 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:ntpgraphic.LineChart.java
public static void NTPClient(String[] servers, int i) { 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 (servers.length == 0) { System.err.println("Usage: NTPClient <hostname-or-address-list>"); System.exit(1);//from w w w . ja v a2 s . c o 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 : servers) { System.out.println(); try { InetAddress hostAddr = InetAddress.getByName(arg); System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress()); TimeInfo info = client.getTime(hostAddr); processResponse(info, i); } 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:com.cellbots.logger.localServer.LocalHttpServer.java
/** * Returns the IP addresses of this device. * /*from www. j a va 2 s.c o m*/ * @return IP addresses as a String. Addresses are separated by newline. */ public static String getLocalIpAddresses() { String ipAddresses = ""; try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { String ipAddress = inetAddress.getHostAddress().toString(); if (ipAddress.split("\\.").length == 4) { ipAddresses = ipAddresses + ipAddress + ":8080\n"; } } } } } catch (SocketException ex) { Log.e("", ex.toString()); } return ipAddresses; }