Port Scanner
Posted by Xingjuan
Last Updated: July 02, 2012
import java.net.*;
import java.io.IOException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

    public class PScanner {
    
         public static void main(String[] args) {
         InetAddress ia=null;
         String host=null;
             try {
            
             host=JOptionPane.showInputDialog("Enter the Host name to scan:\n example: xxx.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 = 0; port < 65536; port++) {
                 try {
                 Socket s = new Socket(remote,port);
                 System.out.println("Server is listening on port " + port+ " of " + hostname);
                 s.close();
             }
                 catch (IOException ex) {
                 // The remote host is not listening on this port
                 System.out.println("Server is not listening on port " + port+ " of " + hostname);
             }
         }
     }
}
Related Content
WiFi Scanner using C#
WiFi Scanner using C#
Samath | Jan 01, 2016
Enable/Disable USB Port using C#
Enable/Disable USB Port using C#
Samath | Dec 28, 2016