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; } } }