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