fuliqi
2024-08-19 9a4549c0c2dbe44c9568fe56fb4df8d6fbb44d4f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.ycl.utils.ip;
 
import lombok.extern.slf4j.Slf4j;
 
import java.io.IOException;
import java.net.InetAddress;
 
/**
 * ping
 *
 * @author:xp
 * @date:2024/8/19 11:11
 */
@Slf4j
public class PingUtil {
 
    /**
     * ping
     *
     * @param ip 目标ip地址
     * @param timeoutSed 超时时间
     * @return 是否在线
     */
    public static Boolean ping(String ip, Integer timeoutSed) {
        try {
            return InetAddress.getByName(ip).isReachable(timeoutSed * 1000);
        } catch (IOException e) {
            log.error("未知的IP地址");
            return Boolean.FALSE;
        }
    }
 
}