Published in: Java
URL: http://snipplr.com/
Requires: Java + Unix "Ping" Program + Root Access to Ping Program Description: Takes 1 argument, which is the number of random IP Adrresses to ping to. It pings each address 1 time with a timeout of 3 seconds. It only displays the ping information when successful, otherwise just displays ".".
Expand |
Embed | Plain Text
import java.io.*; public class Pinger{ int iter = 100; if(args.length>0){ try{ } iter = 100; } } int[] subs = new int[4]; for(int i = 0; i < iter; i++){ host=""; for(int j = 0; j < 4; j++){ subs[j] = num.nextInt(255); } host = subs[0]+"."+subs[1]+"."+subs[2]+"."+subs[3]; ping(host); } } try { StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { sb.append(line); sb.append("\n"); } if(sb.toString().matches(".*0% packet loss.*")){ }else{ } e.printStackTrace(); } } }
You need to login to post a comment.

