我可以加快扫描端口进程吗?

发布于 2024-08-12 05:24:22 字数 1285 浏览 3 评论 0原文

import java.net.*;

import java.io.IOException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class PortScanner {

     public static void main(String[] args) {
     InetAddress ia=null;
     String host=null;
         try {

         host=JOptionPane.showInputDialog("Enter the Host name to scan:\n example: example.com");
             if(host!=null){
             ia = InetAddress.getByName(host);
         scan(ia); }
     }
         catch (UnknownHostException e) {
         System.err.println(e );
     }
     System.out.println("Bye from NFS");
     //System.exit(0);
 }

    public static void scan(final InetAddress remote) {
    //variables for menu bar

    int port=0;
    String hostname = remote.getHostName();

         for ( port = 70; port < 65536; port++) {
             try {
             Socket s = new Socket(remote,port);
             System.out.println("Server is listening on port " + port+ " of " + hostname);
             s.close();
             break;
         }
             catch (IOException ex) {
             // The remote host is not listening on this port
             System.out.println("Server is not listening on port " + port+ " of " + hostname);
         }
     }//for ends
 }
}

请帮我。

import java.net.*;

import java.io.IOException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class PortScanner {

     public static void main(String[] args) {
     InetAddress ia=null;
     String host=null;
         try {

         host=JOptionPane.showInputDialog("Enter the Host name to scan:\n example: example.com");
             if(host!=null){
             ia = InetAddress.getByName(host);
         scan(ia); }
     }
         catch (UnknownHostException e) {
         System.err.println(e );
     }
     System.out.println("Bye from NFS");
     //System.exit(0);
 }

    public static void scan(final InetAddress remote) {
    //variables for menu bar

    int port=0;
    String hostname = remote.getHostName();

         for ( port = 70; port < 65536; port++) {
             try {
             Socket s = new Socket(remote,port);
             System.out.println("Server is listening on port " + port+ " of " + hostname);
             s.close();
             break;
         }
             catch (IOException ex) {
             // The remote host is not listening on this port
             System.out.println("Server is not listening on port " + port+ " of " + hostname);
         }
     }//for ends
 }
}

please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长梦不多时 2024-08-19 05:24:22

我不确定这是否会加快速度,但由于您创建的每个套接字都独立于下一个套接字,因此您是否尝试过创建更多线程,以便在旧套接字等待握手完成时可以创建新套接字。

I am not sure if this will speed things up, but since each socket your making is independent of the next socket, have you tried making more threads so that you can create new sockets when older sockets are waiting for their handshake to complete.

对你的占有欲 2024-08-19 05:24:22

而不是使用该行,

Socket s = new Socket(remote,port);

您应该使用

Socket s = new Socket();
int timeout = 100; // milliseconds
s.connect( new InetSocketAddress( remote, port ), timeout );

这种方式,您不必等待默认的 TCP 超时即可看到该端口被防火墙阻止而没有任何响应。

Instead of using the line

Socket s = new Socket(remote,port);

You should use

Socket s = new Socket();
int timeout = 100; // milliseconds
s.connect( new InetSocketAddress( remote, port ), timeout );

This way you won't have to wait for the default TCP timeout to see that this port is blocked by a firewall without any response.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文