Java Implementation ping IP address

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.