2 package org
.de
.metux
.ip
;
4 import org
.de
.metux
.util
.Exec
;
5 import org
.de
.metux
.util
.ShellEscape
;
14 private class callback
implements Exec
.IExecCallback
16 public void OutputLine(String line
)
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);
32 else if (line
.indexOf("ping statistics")>0);
33 else if (line
.indexOf("packets transmitted")>0);
34 else if (line
.equals(""));
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
));