java 简单的端口扫描

java 简单的端口扫描,第1张

import java.net.*;
import java.io.IOException;

public class ScannerPort //extends Thread {
{
    static String ip = "xxx";

    public static void main(String[] args) {
        for (int i = 10000; i < 12000; i++) {
            test(i);
        }
    }

    public static void test(int port) {
        SocketAddress socketAddress = new InetSocketAddress(ip, port);
        try {
            Socket client = new Socket(); //new Socket(ip, port);
            client.connect(socketAddress, 100);//连不上的0.1秒断掉连接
            //client.setSoTimeout(100); //其实这个是响应阻塞超时,是client和服务端建立连接后,等待接收数据的超时时间,真正的连接超时不是在这里设置

            //如果client不为空,说明该端口对外开放, 否则该端口没有在监听的服务,或者是该端口对外屏蔽。
            if (client != null) {
                System.out.println(" ------------- Port :" + port + " is OK!!!");
            } else {
                System.out.print(port + ",");
            }
        } catch (Exception e2) {
            System.out.print(port + ",");
        }
    }
}

socket 连接超时处理 java_qq_4219790085的博客-CSDN博客_socket连接超时怎么解决啊

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/738156.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-28
下一篇 2022-04-28

发表评论

登录后才能评论

评论列表(0条)

保存