|
20 | 20 | * for both Windows and Unix-like systems. |
21 | 21 | * |
22 | 22 | * <p>Usage: |
| 23 | + * |
23 | 24 | * <ul> |
24 | | - * <li>ping <hostname> : Ping with default count (4 packets)</li> |
25 | | - * <li>ping <hostname> -t : Ping continuously until stopped (Windows/Unix)</li> |
26 | | - * <li>ping <hostname> -n <count> : Ping with specified packet count</li> |
27 | | - * <li>ping <hostname> -w <timeout> : Set timeout in milliseconds (Windows)</li> |
28 | | - * <li>ping <hostname> -l <size> : Set buffer size (Windows)</li> |
| 25 | + * <li>ping <hostname> : Ping with default count (4 packets) |
| 26 | + * <li>ping <hostname> -t : Ping continuously until stopped (Windows/Unix) |
| 27 | + * <li>ping <hostname> -n <count> : Ping with specified packet count |
| 28 | + * <li>ping <hostname> -w <timeout> : Set timeout in milliseconds (Windows) |
| 29 | + * <li>ping <hostname> -l <size> : Set buffer size (Windows) |
29 | 30 | * </ul> |
30 | 31 | * |
31 | 32 | * <p>Examples: |
| 33 | + * |
32 | 34 | * <ul> |
33 | | - * <li>ping google.com</li> |
34 | | - * <li>ping 8.8.8.8</li> |
35 | | - * <li>ping google.com -n 10</li> |
36 | | - * <li>ping google.com -t</li> |
37 | | - * <li>ping 1.1.1.1 -n 5 -w 1000</li> |
| 35 | + * <li>ping google.com |
| 36 | + * <li>ping 8.8.8.8 |
| 37 | + * <li>ping google.com -n 10 |
| 38 | + * <li>ping google.com -t |
| 39 | + * <li>ping 1.1.1.1 -n 5 -w 1000 |
38 | 40 | * </ul> |
39 | 41 | * |
40 | 42 | * <p>Statistics displayed: |
| 43 | + * |
41 | 44 | * <ul> |
42 | | - * <li>Packets: Sent, Received, Lost (with percentage)</li> |
43 | | - * <li>Round-trip times: Minimum, Maximum, Average</li> |
| 45 | + * <li>Packets: Sent, Received, Lost (with percentage) |
| 46 | + * <li>Round-trip times: Minimum, Maximum, Average |
44 | 47 | * </ul> |
45 | 48 | * |
46 | 49 | * <p>Note: This implementation uses the system's native ping command for accurate network |
@@ -108,8 +111,7 @@ private void displayHelp() { |
108 | 111 | System.out.println( |
109 | 112 | " -w timeout Timeout in milliseconds to wait for each reply."); |
110 | 113 | } else { |
111 | | - System.out.println( |
112 | | - " -c count Number of echo requests to send (Unix-style)."); |
| 114 | + System.out.println(" -c count Number of echo requests to send (Unix-style)."); |
113 | 115 | System.out.println( |
114 | 116 | " -i interval Wait interval seconds between sending each packet."); |
115 | 117 | } |
@@ -154,8 +156,7 @@ private void executePing(String[] command, String host, String resolvedIP) |
154 | 156 | ProcessBuilder pb = new ProcessBuilder(command); |
155 | 157 | Process process = pb.start(); |
156 | 158 |
|
157 | | - BufferedReader reader = |
158 | | - new BufferedReader(new InputStreamReader(process.getInputStream())); |
| 159 | + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
159 | 160 | BufferedReader errorReader = |
160 | 161 | new BufferedReader(new InputStreamReader(process.getErrorStream())); |
161 | 162 |
|
@@ -212,7 +213,8 @@ private void extractTimeFromLine(String line, PingStatistics stats, String os) { |
212 | 213 | } |
213 | 214 |
|
214 | 215 | // Count sent/received packets |
215 | | - if (line.toLowerCase().contains("reply from") || line.toLowerCase().contains("bytes from")) { |
| 216 | + if (line.toLowerCase().contains("reply from") |
| 217 | + || line.toLowerCase().contains("bytes from")) { |
216 | 218 | stats.received++; |
217 | 219 | stats.sent++; |
218 | 220 | } else if (line.toLowerCase().contains("request timed out") |
|
0 commit comments