• ping批量端口


    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     * Description TestRemotePort
     * Date 2021/11/20
     * Created by www.ij34.com
     */
    public class TestRemotePort {
        public static void main(String[] args) {
            List<Integer> list = new ArrayList<>();
            //ping的端口
            for (int i = 1; i <= 1000; i++) {
                list.add(i);
            }
            int threads = 50;//线程数
            int start = 0;
            int size = list.size() / threads;
            for (int i = 1; i <= threads; i++) {
                new Thread(new ThreadTask(list.subList(start, (start + size) > list.size() ? list.size() : start + size))).start();
                start += size;
            }
    
    
        }
    
    
        private static class ThreadTask implements Runnable {
            List list;
    
            public ThreadTask(List<Integer> list2) {
                list = list2;
            }
    
            @Override
            public void run() {
                list.forEach(c -> {
                    boolean b = reachableIP("f2od82dan8xypungixks.okefafs.com",(Integer) c);
                    if (b) {
                        System.out.println(Thread.currentThread().getId() + "线程成功端口---------------" + c);
                    } else {
    //                    System.out.println(Thread.currentThread().getId()  + "|" + c);
                    }
                });
            }
    
            boolean reachableIP(String url,int port) {
                String cmd = "tcping -n 1 "+url+" " + port;
                try {
                    Process p = Runtime.getRuntime().exec(cmd);
                    InputStream is = p.getInputStream();
                    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                    String line;
                    reader.readLine();
                    String str = reader.readLine();
                    try {
                        p.waitFor();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    is.close();
                    reader.close();
                    p.destroy();
                    return str.contains("Port is open") ? true : false;
                } catch (IOException e) {
                    e.printStackTrace();
                    return false;
                }
            }
        }
    }
    --------------------------------------------------------------------------------------------------------------------------------------------

    作者:Honey_Badger —— 觉得这文章好,点一下左下角

    出处:http://tk55.cnblogs.com/

  • 相关阅读:
    python:递归函数(汉诺塔)
    python:代码复用与函数递归
    unity接入平台sdk
    原型和原型链
    闭包js
    微信小游戏的排行榜重点
    微信简单的排行榜
    代理服务器出现问题解决方案
    nodejs的fs模块
    nodejs的l分数
  • 原文地址:https://www.cnblogs.com/tk55/p/15584232.html
Copyright © 2020-2023  润新知