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


    转: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;
        }
  • 相关阅读:
    网页导出PDF文件
    图片翻转导航
    瀑布流之ajax
    楼梯效果
    数码时钟
    数字字母随机验证码
    kafka shell
    zookeeper shell
    正则
    Linux(一)
  • 原文地址:https://www.cnblogs.com/jvStarBlog/p/12174479.html
Copyright © 2020-2023  润新知