我用一个javasocket端口扫描的方法来检查某一服务器上的端口号为8080的tomcat是否启用,程序如下。但我发现无论测试的tomcat是否打开,返回的结果都是“portisopen”!如果把8080端口...
我用一个java socket端口扫描的方法来检查某一服务器上的端口号为8080的tomcat是否启用,程序如下。但我发现无论测试的tomcat是否打开,返回的结果都是“port is open”!如果把8080端口改成其他任何端口都能成功测试出端口的开启与关闭,只有8080端口不行,谁能告诉我这是为什么呢?今天之内帮我解决问题的有加分!
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.*;
import java.util.*;
public class SocketPort {
public static void main(String[] args) throws IOException {
String ip = "162.105.211.143"; //目标服务器ip地址
int port=8080; //服务器上的tomcat端口号
String hostname = new String();
try{ //get the target ip address and hostname
InetAddress address = InetAddress.getByName(ip);
hostname = address.getHostName();
}
catch(UnknownHostException e)
{
System.out.println("Could not find "+ ip);
}
System.out.println("Information Of The Port On the " + hostname +"computer ");
// do ports scan
//for(int port = 8077;port < 8092;++port)
//{
try
{
Socket s = new Socket(hostname,port);
System.out.println("The port " + port + " is open!");
System.out.println("Connected to "+ s.getInetAddress() + " on port " + s.getPort() + " from port "+ s.getLocalPort() + " of " + s.getLocalAddress());
}
catch(IOException e)
{
System.out.println("The port " + port + " is closed!");
}
}
//}
}
展开