1 /*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6 package example;
7
8 import java.io.IOException;
9 import java.net.InetAddress;
10
11 /**
12 *
13 * @author silianbo
14 */
15 public class test {
16
17 public static void main(String[] args) throws IOException {
18 String ip = "192.168.1.";
19 for (int i = 1; i < 256; i++) {
20 String host = ip + i;
21 InetAddress ia = InetAddress.getByName(host);
22 boolean bool = ia.isReachable(1500);
23 if (bool) {
24 System.out.println("主机: " + host + " 可用");
25 }
26
27 }
28
29 }
30 }