gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:53:47 32 4
gpt4 key购买 nike

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
}
}

请帮助我。

最佳答案

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

关于java - 我可以加快扫描端口进程吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1806954/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com