hello friends,
today we are going to learn about ping IP address using java in android application. we need to use some library so using it we can ping ip.
let's take an example.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class MyHostName {
public static void runSystemCommand(String command) {
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader inputStreamdata = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String s = "";
String keyword="Destination";
String keyword_Request = "Request";
// reading output stream of the command
while ((s = inputStreamdata.readLine()) != null) {
if(s.contains(keyword) || s.contains(keyword_Request))
{
System.out.println("response " + "OFFLINE");
}else{
System.out.println("response " +s);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String ip = "192.168.0.16";
runSystemCommand("ping " + ip);
}
}
today we are going to learn about ping IP address using java in android application. we need to use some library so using it we can ping ip.
let's take an example.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class MyHostName {
public static void runSystemCommand(String command) {
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader inputStreamdata = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String s = "";
String keyword="Destination";
String keyword_Request = "Request";
// reading output stream of the command
while ((s = inputStreamdata.readLine()) != null) {
if(s.contains(keyword) || s.contains(keyword_Request))
{
System.out.println("response " + "OFFLINE");
}else{
System.out.println("response " +s);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String ip = "192.168.0.16";
runSystemCommand("ping " + ip);
}
}
Comments
Post a Comment