Back to project page AndroidGraph.
The source code is released under:
MIT License
If you think the Android project AndroidGraph 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 com.nimble.android_graph.generics; //from ww w .jav a2s . c o m import android.util.Log; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; /** * A Class for testing basic network functionality * * @author Michael Leith * @since 02/07/2014. * @version 1.0 */ public class testingSuite { /** * Pings the provided address. Put this in a thread. * @param pingAddr String * @param time final int */ 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()); } } }