Authoring tool classes Pingutil Other programs can be called Through the class name:
public class Pingiputil {
private static Logger Logger =logger.getlogger (pingiputil.class);
public static Boolean Pingip (String mdmc,string ipadd) throws exception{
Gets the current Process object
Runtime Runtime=runtime.getruntime ();
Process Process=null; Declaring a processing class object
String Line=null; Return line information
InputStream Is=null; Input stream
InputStreamReader Isr=null; BYTE stream
BufferedReader Br=null; Character Stream
Boolean Res=false; Results
try{
Process=runtime.exec ("ping" +ipadd); ping command
Is=process.getinputstream (); Instantiate a Stream
Isr=new InputStreamReader (IS); The input stream is converted into a byte stream
Br=new BufferedReader (ISR); Reading text from bytes
while ((Line=br.readline ())!=null) {
if (Line.contains ("TTL")) {
Res=true;
Break
}
}
Is.close ();
Br.close ();
Isr.close ();
}catch (Exception e) {
Logger.error ("Ping store IP failed!") Reason: "+e.getmessage ()");
throw new RuntimeException (e);
}
return res;
}
}
This method is inefficient, but it is well understood!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Implementation ping IP address