Public Static Longcalspeed (String IP) {Runtime runtime= Runtime.getruntime ();//Gets the current program's run-in objectProcess Process =NULL;//declaring a processing class objectString line =NULL;//Return line informationInputStream is =NULL;//input StreamInputStreamReader ISR =NULL;//Byte streamBufferedReader br =NULL; Try{Process= Runtime.exec ("ping" + IP + "-W 1000");//PINGis = Process.getinputstream ();//instantiating an input streamISR =NewInputStreamReader (IS);//Convert input flow to byte streamBR =NewBufferedReader (ISR);//reading text from bytes while(line = Br.readline ())! =NULL) { if(Line.contains ("TTL")) { intBegin = Line.indexof ("ttl="); String value= Line.substring (begin+4, Line.length ()); returninteger.valueof (value); } } } Catch(IOException e) {System.out.println (e); Runtime.exit (1); }finally{ if(is!=NULL){ Try{is.close (); } Catch(IOException e) {}}if(isr!=NULL){ Try{isr.close (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } if(br!=NULL){ Try{br.close (); } Catch(IOException e) {e.printstacktrace (); } } } return10000; }
Java Test IP