01: /**
02:  * Verilen adrese ping atan fonksiyonu bulunduran
03:  * siniftir.
04:  * @author aatay EB
05:  * @version 1.0
06:  */
07: public class Pinger {
08: 
09:         public static void main(String arg[]) {
10: 
11:                 boolean ulasilabilir_mi = false;
12:                 String ip_adresleri[] = new String[]{"10.0.0.1",
13:                                 "10.0.0.2","10.0.0.3","10.0.0.4","10.0.0.5",
14:                                 "10.0.0.6","10.0.0.7"};
15:                 for(int i=0;i<ip_adresleri.length;i++)
16:                 {
17:                         System.out.print("IP Adresi: "+ip_adresleri[i]+" ");
18:                         try {
19:                                 ulasilabilir_mi = windows_ping(ip_adresleri[i]);
20:                         } catch (Exception e) {
21:                                 // TODO Auto-generated catch block
22:                                 e.printStackTrace();
23:                         }
24:                         if(ulasilabilir_mi)
25:                                 System.out.println("Ulasilabilir...");
26:                         else
27:                                 System.out.println("Ulasilamaz!");
28:                 }
29:         }
30: 
31:         /**
32:          * Girilen ip adresinin, online olup olmadigina bakar.
33:          * @param ip Kontrol edilecek ip adresi
34:          * @return online ise true, offline ise false doner.
35:          * @throws Exception
36:          */
37:         public static boolean windows_ping(String ip) throws Exception {
38:                 Process p =
39:                         Runtime.getRuntime().exec("ping -n 1 -w 100 -l 8 " + ip);
40:                 int status = p.waitFor();
41:                 return status==0?true:false;
42:         }
43: }