默认IP的设备已开放ping功能
代码
public class PingTest {
public static void main(String[] args) throws Exception {
String ip = "192.168.21.101";
boolean reachable = InetAddress.getByName(ip).isReachable(3000);
System.out.println(ip + (reachable ? " 可达" : " 不可达"));
}
}