• 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/

  • 相关阅读:
    SQL中的数字格式化 (收藏)
    read about用法
    run into用法
    shoot for用法
    take off用法
    英语成语
    bring up用法
    satisfy with用法
    spend用法
    Linux环境进程间通信:共享内存
  • 原文地址:https://www.cnblogs.com/tk55/p/15584232.html
Copyright © 2020-2023  润新知