Back to project page Android-Wireless.
The source code is released under:
MIT License
If you think the Android project Android-Wireless listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package generics; /*w w w . j a v a2 s .c o m*/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; import android.util.Log; /** * A Class for testing basic network functionality * @author Michael Leith */ public class testingSuite { /** * Pings the provided address. * Put in a thread!! * @param pingAddr */ static public final void runPing(final String pingAddr, final int time) { //String pingResult = ""; new Thread(new Runnable(){ public void run() { String pingCmd = "ping " + pingAddr; try { Runtime r = Runtime.getRuntime(); //Process p = r.exec(pingCmd); BufferedReader in = new BufferedReader(new InputStreamReader( r.exec(pingCmd).getInputStream()) );//p.getInputStream())); String inputLine; int i = 0; while ((inputLine = in.readLine()) != null && i < time) { Log.d("ping", inputLine); i++; // pingResult += inputLine; } in.close(); } catch (IOException e) { Log.e("runPing", e.toString()); } } }).start(); } /** * Gets the current Ip Address, printing it to logcat with the tage "Ip Address" */ static public final void getIpAddress() { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); if (intf.getName().contains("wlan")) { for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr .hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress() && (inetAddress.getAddress().length == 4)) { Log.d("Ip Address", inetAddress.getHostAddress()); } } } } } catch (Exception e) { Log.e("Ip Address", e.toString()); } } }