Makefile added / pkg-config descriptor
[metux-java.git] / ip / Ping.java
blob0fe64a2c9af47a8c259f6c7cbe00a0d660424331
2 package org.de.metux.ip;
4 import org.de.metux.util.Exec;
5 import org.de.metux.util.ShellEscape;
7 public class Ping
9 String hostname;
10 int max = 5;
11 Exec exec;
12 boolean alive;
14 private class callback implements Exec.IExecCallback
16 public void OutputLine(String line)
18 line = line.trim();
20 if (line.startsWith("PING "))
22 line = line.substring(5);
23 // System.err.println(" --> PING HEAD: "+line);
24 int x = line.indexOf(" ");
26 else if (line.indexOf(" octets from ")>0)
28 // System.out.println("PING REPLY: "+line);
29 alive = true;
30 exec.abort();
32 else if (line.indexOf("ping statistics")>0);
33 else if (line.indexOf("packets transmitted")>0);
34 else if (line.equals(""));
35 else
36 System.out.println(">>"+line);
39 public void ErrorLine(String line)
41 System.err.println("!> "+line);
44 public void debug(String line)
48 public void error(String line)
50 System.err.println("EXEC ERROR: "+line);
54 public Ping(String my_hostname)
56 hostname = my_hostname;
59 public boolean tryHostAlive()
61 exec = new Exec(new callback());
62 exec.run("ping -c "+max+" "+ShellEscape.quoting(hostname));
63 return alive;