首页 > 编程语言 > 详细

java--判断ip、端口是连通性

时间:2020-01-10 10:19:35      阅读:471      评论:0      收藏:0      [点我收藏+]

转:https://www.cnblogs.com/chenchaochao/p/5522654.html

判断ip、端口连通性

public static boolean isHostConnectable(String host, int port) {
        Socket socket = new Socket();
        try {
            socket.connect(new InetSocketAddress(host, port));
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        } finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return true;
    }

判断ip连通性

public static boolean isHostReachable(String host, Integer timeOut) {
        try {
            return InetAddress.getByName(host).isReachable(timeOut);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }

java--判断ip、端口是连通性

原文:https://www.cnblogs.com/jvStarBlog/p/12174479.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!