我也帮你顶,我也碰到这样的问题了?
楼主你的问题解决了吗?

解决方案 »

  1.   

    //用下面的程序可以判断服务器端口是否已开import java.io.*; 
    import java.net.*; 
    import java.util.*; 
    public class SocketPort { public static void main(String[] args) { String ip = "192.168.20.104"; 
    String hostname = new String(); try{ //get the target ip address and hostname 
    InetAddress address = InetAddress.getByName(ip); 
    System.out.println(address); 
    hostname = address.getHostName(); 
    System.out.println(hostname); 

    catch(UnknownHostException e) 

    System.out.println("Could not find "+ ip); } 
    try 
    { // creat the output file 
    PrintWriter fout = new PrintWriter( new FileWriter("PortInf.txt")); 
    fout.println("Information Of The Port On the " + hostname +"computer "); 
    fout.println(); // do ports scan 
    for(int nport = 25;nport < 30;++nport) 

    try 
    { Socket s = new Socket(hostname,nport); 
    fout.println("The port " + nport + " is open!"); fout.println("Connected to "+ s.getInetAddress() + " on port " + s.getPort() + " from port "+ s.getLocalPort() + " of " + s.getLocalAddress()); 
    //print the connected socket information 
    } catch(IOException e) 

    fout.println("The port " + nport + " is closed!"); 
    } } 
    fout.close(); } 
    catch(IOException e){} }