Hello Friends
edit = (EditText) findViewById(R.id.editText1);
edit.setText("192.168.1.1");
text = (TextView) findViewById(R.id.textView1);
Here is the button that has the code behind it. The following code returns a string as output in which we whether the server is reachable or not.
it works fine for "192.168.1.1" and "192.168.1.123"
but when i put like "google.comse" . "192.168.1.1tgh" and etc..
The ocde does not work.
Please give some suggestions .
public void btn_PingClicked(View view) {
Editable host = edit.getText();
try {
String pingCmd = "ping -c 5 " + host;
String pingResult = "";
Runtime r = Runtime.getRuntime();
Process p = r.exec(pingCmd);
BufferedReader in = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
text.setText(inputLine + "\n\n");
pingResult += inputLine;
text.setText(pingResult);
}
in.close();
}// try
catch (IOException e) {
System.out.println(e);
}
String FinalPingText = text.getText().toString();
if (FinalPingText != null) {
// Toast.makeText(getApplicationContext(), "Check FinalPingText" +
// FinalPingText , Toast.LENGTH_LONG).show();
List<String> tokens = new ArrayList<String>();
tokens.add("UnreachableFrom");
tokens.add("Unreachable---");
tokens.add("Unreachable");
String patternString = "\\b(" + StringUtils.join(tokens, "|")
+ ")\\b";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(FinalPingText);
if (matcher.find() == false) {
Toast.makeText(getApplicationContext(), "Sever Found",
Toast.LENGTH_LONG).show();
}
while (matcher.find()) {
Toast.makeText(getApplicationContext(), "Sever not Found",
Toast.LENGTH_LONG).show();
}
}
}
Your truly,
Hasnain Ahmad
edit = (EditText) findViewById(R.id.editText1);
edit.setText("192.168.1.1");
text = (TextView) findViewById(R.id.textView1);
Here is the button that has the code behind it. The following code returns a string as output in which we whether the server is reachable or not.
it works fine for "192.168.1.1" and "192.168.1.123"
but when i put like "google.comse" . "192.168.1.1tgh" and etc..
The ocde does not work.
Please give some suggestions .
public void btn_PingClicked(View view) {
Editable host = edit.getText();
try {
String pingCmd = "ping -c 5 " + host;
String pingResult = "";
Runtime r = Runtime.getRuntime();
Process p = r.exec(pingCmd);
BufferedReader in = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
text.setText(inputLine + "\n\n");
pingResult += inputLine;
text.setText(pingResult);
}
in.close();
}// try
catch (IOException e) {
System.out.println(e);
}
String FinalPingText = text.getText().toString();
if (FinalPingText != null) {
// Toast.makeText(getApplicationContext(), "Check FinalPingText" +
// FinalPingText , Toast.LENGTH_LONG).show();
List<String> tokens = new ArrayList<String>();
tokens.add("UnreachableFrom");
tokens.add("Unreachable---");
tokens.add("Unreachable");
String patternString = "\\b(" + StringUtils.join(tokens, "|")
+ ")\\b";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(FinalPingText);
if (matcher.find() == false) {
Toast.makeText(getApplicationContext(), "Sever Found",
Toast.LENGTH_LONG).show();
}
while (matcher.find()) {
Toast.makeText(getApplicationContext(), "Sever not Found",
Toast.LENGTH_LONG).show();
}
}
}
Your truly,
Hasnain Ahmad