hi, can you help me

2 views
Skip to first unread message

subbu

unread,
Jun 26, 2009, 8:59:39 PM6/26/09
to "Code For Freedom" Contest Participants
can you tell me how to give "ping" from the java application and how
to store it in a file dynamically, which means when i give a new ping
again the file must note the changes.

arun singh

unread,
Jun 26, 2009, 11:29:30 PM6/26/09
to CodeFor...@googlegroups.com
Hello There,


Try This code,may be u can get some idea & configure according to your needs


--------------------------------------------


import java.net.*;
import java.io.*;
import java.util.*;

public class pingTest {

public static void main(String[] args) {

String ip = args[0];
String pingResult = "";

String pingCmd = "ping " + ip;

try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(pingCmd);

BufferedReader in = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
pingResult += inputLine;
}
in.close();

}//try
catch (IOException e) {
System.out.println(e);
}

}

}
--------------------------
Code 2:  Code for Simply Pinging a Server



import java.io.*;
import java.net.*;

     public class PseudoPing {
         public static void main(String args[]) {
             try {
             Socket t = new Socket(args[0], 7);
             DataInputStream dis = new DataInputStream(t.getInputStream());
             PrintStream ps = new PrintStream(t.getOutputStream());
             ps.println("Hello");
             String str = is.readLine();
             if (str.equals("Hello"))
             System.out.println("Alive!") ;
             else
             System.out.println("Dead or echo port not responding");
             t.close();
         }
             catch (IOException e) {
         e.printStackTrace();}
     }
}

-------------------

I Hope those codes will give you some idea to Generate code in your neurons :)



--
Regards
Arun
Reply all
Reply to author
Forward
0 new messages