import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
@RestController
public class NetCheckController {
@GetMapping("/testConnect")
public boolean hello(@RequestParam(value = "ip") String ip, @RequestParam(value = "port") int port) {
Socket socket = new Socket();
try {
socket.connect(new InetSocketAddress(ip, port), 1000);
return true;
} catch (IOException exception) {
return false;
} finally {
try {
socket.close();
} catch (IOException e) {
return false;
}
}
}
}
java判断、测试ip和端口是否可连接 服务是否可连接
最新推荐文章于 2023-05-24 11:06:53 发布